Skip to content

Commit

Permalink
chore: Sépare les migrations prisma de la webapp et de l'ELT
Browse files Browse the repository at this point in the history
Car les deux écrivent dans des schémas séparés, et que la feature
"multiSchema" de prisma est encore en preview et ne supporte pas les
migration (on a eu des erreurs PG 42P07 lors des prisma migrate reset)

- prisma/prisma#15077 (comment)
  • Loading branch information
sroccaserra committed Dec 2, 2022
1 parent a5cf70c commit 004c4b0
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 55 deletions.
10 changes: 10 additions & 0 deletions data/README.md
Expand Up @@ -23,6 +23,16 @@ data/input_data/
└── views
```

# Initialisation de la base de données

Pré-requis : avoir configuré et initialisé votre base de données de Webapp comme précisé dans le README.md de la racine.

Sur un poste de dev, depuis le répertoire data :

```bash
npx prisma migrate dev
```

# Schéma des flux de données

Ce document souhaite poser les bases des flux de données alimentant l'application [Pilote 2](). @Fabien ajouter lien vers l'app
Expand Down
@@ -1,8 +1,5 @@
-- CreateSchema
CREATE SCHEMA IF NOT EXISTS "raw_data";

-- CreateTable
CREATE TABLE "raw_data"."metadata_chantier" (
CREATE TABLE "metadata_chantier" (
"chantier_id" TEXT NOT NULL,
"ch_code" TEXT,
"ch_descr" TEXT,
Expand All @@ -19,28 +16,11 @@ CREATE TABLE "raw_data"."metadata_chantier" (
);

-- CreateTable
CREATE TABLE "raw_data"."metadata_perimetre" (
CREATE TABLE "metadata_perimetre" (
"perimetre_id" TEXT NOT NULL,
"per_nom" TEXT NOT NULL,
"per_short" TEXT,
"per_picto" TEXT,

CONSTRAINT "metadata_perimetre_pkey" PRIMARY KEY ("perimetre_id")
);

-- CreateTable
CREATE TABLE "public"."chantier" (
"id" TEXT NOT NULL,
"nom" TEXT NOT NULL,
"id_perimetre" TEXT NOT NULL,

CONSTRAINT "chantier_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "public"."perimetre" (
"id" TEXT NOT NULL,
"nom" TEXT NOT NULL,

CONSTRAINT "perimetre_pkey" PRIMARY KEY ("id")
);
3 changes: 3 additions & 0 deletions data/prisma/migrations/migration_lock.toml
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
32 changes: 32 additions & 0 deletions data/prisma/schema.prisma
@@ -0,0 +1,32 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("ELT_DATABASE_URL")
}

model metadata_chantier {
chantier_id String @id
ch_code String?
ch_descr String?
ch_nom String
ch_ppg String
ch_perseverant String?
porteur_shorts_noDAC String
porteur_ids_noDAC String
porteur_shorts_DAC String?
porteur_ids_DAC String?
ch_per String
}

model metadata_perimetre {
perimetre_id String @id
per_nom String
per_short String?
per_picto String?
}
15 changes: 15 additions & 0 deletions data/prisma/seed.ts
@@ -0,0 +1,15 @@
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function main() {
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (error) => {
console.error(error);
await prisma.$disconnect();
process.exit(1);
});
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -20,7 +20,7 @@
"test:server": "npm run test:server:unit && npm run test:server:integration",
"test:server:unit": "jest src/server/.*.unit.test.* src/utils/.*.unit.test.*",
"test:server:integration": "jest --config=jest.integration.config.js src/server/.*.integration.test.*",
"database:init": "prisma db execute --file scripts/drop.sql && prisma migrate reset"
"database:init": "prisma migrate reset"
},
"browserslist": {
"production": [
Expand Down
16 changes: 16 additions & 0 deletions prisma/migrations/20221202143013_init/migration.sql
@@ -0,0 +1,16 @@
-- CreateTable
CREATE TABLE "chantier" (
"id" TEXT NOT NULL,
"nom" TEXT NOT NULL,
"id_perimetre" TEXT NOT NULL,

CONSTRAINT "chantier_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "perimetre" (
"id" TEXT NOT NULL,
"nom" TEXT NOT NULL,

CONSTRAINT "perimetre_pkey" PRIMARY KEY ("id")
);
31 changes: 0 additions & 31 deletions prisma/schema.prisma
Expand Up @@ -3,51 +3,20 @@

generator client {
provider = "prisma-client-js"
previewFeatures = ["multiSchema"]
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
schemas = ["raw_data", "public"]
}

model metadata_chantier {
chantier_id String @id
ch_code String?
ch_descr String?
ch_nom String
ch_ppg String
ch_perseverant String?
porteur_shorts_noDAC String
porteur_ids_noDAC String
porteur_shorts_DAC String?
porteur_ids_DAC String?
ch_per String
@@schema("raw_data")
}

model metadata_perimetre {
perimetre_id String @id
per_nom String
per_short String?
per_picto String?
@@schema("raw_data")
}

model chantier {
id String @id
nom String
id_perimetre String
@@schema("public")
}

model perimetre {
id String @id
nom String
@@schema("public")
}
1 change: 0 additions & 1 deletion scripts/drop_raw_data.sql

This file was deleted.

0 comments on commit 004c4b0

Please sign in to comment.