Files
ferrovia-panel/migrations/create_infrastructure_reseau.sql
T
AdminGit 935b9cf92b V5.0.0 //
-> Refonte du système de GESTION DES ROULEMENTS de matériels roulants
-> Cartographie Infra + Widget
2026-10-04 23:47:21 +02:00

55 lines
2.0 KiB
SQL

-- ============================================================================
-- Migration : Infrastructure du réseau ferroviaire (Ferrovia Panel)
-- ============================================================================
-- 1. Table principale pour l'infrastructure
CREATE TABLE IF NOT EXISTS "public"."infrastructure_reseau" (
"id" uuid DEFAULT gen_random_uuid() NOT NULL PRIMARY KEY,
"version" varchar(20) DEFAULT '1.0' NOT NULL,
"nom_reseau" varchar(255) DEFAULT 'Réseau Ferroviaire Principal',
"region" varchar(100),
"rails" jsonb DEFAULT '[]'::jsonb NOT NULL,
"signaux" jsonb DEFAULT '[]'::jsonb NOT NULL,
"pancartes" jsonb DEFAULT '[]'::jsonb NOT NULL,
"config" jsonb DEFAULT '{}'::jsonb NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT now(),
"updated_at" timestamptz NOT NULL DEFAULT now()
);
-- Index pour recherche rapide
CREATE INDEX IF NOT EXISTS "idx_infra_reseau_region" ON "public"."infrastructure_reseau" ("region");
-- 2. Ajout des colonnes latitude & longitude dans la table gares si nécessaire
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'gares' AND column_name = 'latitude'
) THEN
ALTER TABLE "public"."gares" ADD COLUMN "latitude" double precision;
END IF;
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public' AND table_name = 'gares' AND column_name = 'longitude'
) THEN
ALTER TABLE "public"."gares" ADD COLUMN "longitude" double precision;
END IF;
END $$;
-- 3. RLS (Row-Level Security)
ALTER TABLE "public"."infrastructure_reseau" ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Lecture ouverte infrastructure_reseau"
ON "public"."infrastructure_reseau"
FOR SELECT
TO authenticated, anon
USING (true);
CREATE POLICY "Écriture ouverte infrastructure_reseau"
ON "public"."infrastructure_reseau"
FOR ALL
TO authenticated, anon
USING (true)
WITH CHECK (true);