Skip to content
Snippets Groups Projects
Commit 3158820a authored by Abelangel's avatar Abelangel
Browse files

microservice helloworld supp, migrations de la databases faites par le service auth

parent 2c712fe2
No related branches found
No related tags found
No related merge requests found
Showing
with 57 additions and 269 deletions
-- This is an empty migration.
\ No newline at end of file
/*
Warnings:
- The primary key for the `Reponse` table will be changed. If it partially fails, the table could be left without primary key constraint.
- Added the required column `idReponse` to the `Reponse` table without a default value. This is not possible if the table is not empty.
*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Reponse" (
"idReponse" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"idQuestion" INTEGER NOT NULL,
"idChoix" INTEGER,
"idUser" INTEGER NOT NULL,
"numeric" REAL,
CONSTRAINT "Reponse_idQuestion_fkey" FOREIGN KEY ("idQuestion") REFERENCES "Question" ("idQuestion") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Reponse_idChoix_fkey" FOREIGN KEY ("idChoix") REFERENCES "Choix" ("idChoix") ON DELETE SET NULL ON UPDATE CASCADE,
CONSTRAINT "Reponse_idUser_fkey" FOREIGN KEY ("idUser") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Reponse" ("idChoix", "idQuestion", "idUser", "numeric") SELECT "idChoix", "idQuestion", "idUser", "numeric" FROM "Reponse";
DROP TABLE "Reponse";
ALTER TABLE "new_Reponse" RENAME TO "Reponse";
CREATE UNIQUE INDEX "Reponse_idQuestion_idUser_idChoix_key" ON "Reponse"("idQuestion", "idUser", "idChoix");
PRAGMA foreign_key_check("Reponse");
PRAGMA foreign_keys=ON;
-- This is an empty migration.
\ No newline at end of file
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Choix" (
"idChoix" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"isCorrect" BOOLEAN NOT NULL,
"idQuestion" INTEGER NOT NULL,
"nomChoix" TEXT NOT NULL,
"position" INTEGER NOT NULL,
CONSTRAINT "Choix_idQuestion_fkey" FOREIGN KEY ("idQuestion") REFERENCES "Question" ("idQuestion") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_Choix" ("idChoix", "idQuestion", "isCorrect", "nomChoix", "position") SELECT "idChoix", "idQuestion", "isCorrect", "nomChoix", "position" FROM "Choix";
DROP TABLE "Choix";
ALTER TABLE "new_Choix" RENAME TO "Choix";
CREATE TABLE "new_Reponse" (
"idReponse" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"idQuestion" INTEGER NOT NULL,
"idChoix" INTEGER,
"idUser" INTEGER NOT NULL,
"numeric" REAL,
CONSTRAINT "Reponse_idQuestion_fkey" FOREIGN KEY ("idQuestion") REFERENCES "Question" ("idQuestion") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Reponse_idChoix_fkey" FOREIGN KEY ("idChoix") REFERENCES "Choix" ("idChoix") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "Reponse_idUser_fkey" FOREIGN KEY ("idUser") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Reponse" ("idChoix", "idQuestion", "idReponse", "idUser", "numeric") SELECT "idChoix", "idQuestion", "idReponse", "idUser", "numeric" FROM "Reponse";
DROP TABLE "Reponse";
ALTER TABLE "new_Reponse" RENAME TO "Reponse";
CREATE UNIQUE INDEX "Reponse_idQuestion_idUser_idChoix_key" ON "Reponse"("idQuestion", "idUser", "idChoix");
PRAGMA foreign_key_check("Choix");
PRAGMA foreign_key_check("Reponse");
PRAGMA foreign_keys=ON;
-- This is an empty migration.
\ No newline at end of file
/*
Warnings:
- Added the required column `score` to the `Participer` table without a default value. This is not possible if the table is not empty.
*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Participer" (
"idUser" INTEGER NOT NULL,
"idQCM" INTEGER NOT NULL,
"feedback" TEXT NOT NULL,
"note" REAL NOT NULL,
"score" INTEGER NOT NULL,
"heureDebut" INTEGER NOT NULL,
"hasFinished" BOOLEAN NOT NULL DEFAULT false,
PRIMARY KEY ("idUser", "idQCM"),
CONSTRAINT "Participer_idUser_fkey" FOREIGN KEY ("idUser") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Participer_idQCM_fkey" FOREIGN KEY ("idQCM") REFERENCES "QcmTable" ("idQCM") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Participer" ("feedback", "hasFinished", "heureDebut", "idQCM", "idUser", "note") SELECT "feedback", "hasFinished", "heureDebut", "idQCM", "idUser", "note" FROM "Participer";
DROP TABLE "Participer";
ALTER TABLE "new_Participer" RENAME TO "Participer";
PRAGMA foreign_key_check("Participer");
PRAGMA foreign_keys=ON;
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Participer" (
"idUser" INTEGER NOT NULL,
"idQCM" INTEGER NOT NULL,
"feedback" TEXT NOT NULL,
"note" REAL NOT NULL,
"score" INTEGER,
"heureDebut" INTEGER NOT NULL,
"hasFinished" BOOLEAN NOT NULL DEFAULT false,
PRIMARY KEY ("idUser", "idQCM"),
CONSTRAINT "Participer_idUser_fkey" FOREIGN KEY ("idUser") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Participer_idQCM_fkey" FOREIGN KEY ("idQCM") REFERENCES "QcmTable" ("idQCM") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Participer" ("feedback", "hasFinished", "heureDebut", "idQCM", "idUser", "note", "score") SELECT "feedback", "hasFinished", "heureDebut", "idQCM", "idUser", "note", "score" FROM "Participer";
DROP TABLE "Participer";
ALTER TABLE "new_Participer" RENAME TO "Participer";
PRAGMA foreign_key_check("Participer");
PRAGMA foreign_keys=ON;
/*
Warnings:
- Made the column `score` on table `Participer` required. This step will fail if there are existing NULL values in that column.
*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Participer" (
"idUser" INTEGER NOT NULL,
"idQCM" INTEGER NOT NULL,
"feedback" TEXT NOT NULL,
"note" REAL NOT NULL,
"score" INTEGER NOT NULL,
"heureDebut" INTEGER NOT NULL,
"hasFinished" BOOLEAN NOT NULL DEFAULT false,
PRIMARY KEY ("idUser", "idQCM"),
CONSTRAINT "Participer_idUser_fkey" FOREIGN KEY ("idUser") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Participer_idQCM_fkey" FOREIGN KEY ("idQCM") REFERENCES "QcmTable" ("idQCM") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Participer" ("feedback", "hasFinished", "heureDebut", "idQCM", "idUser", "note", "score") SELECT "feedback", "hasFinished", "heureDebut", "idQCM", "idUser", "note", "score" FROM "Participer";
DROP TABLE "Participer";
ALTER TABLE "new_Participer" RENAME TO "Participer";
PRAGMA foreign_key_check("Participer");
PRAGMA foreign_keys=ON;
-- This is an empty migration.
\ No newline at end of file
-- This is an empty migration.
\ No newline at end of file
/*
Warnings:
- Added the required column `randomOrder` to the `Question` table without a default value. This is not possible if the table is not empty.
*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Question" (
"idQuestion" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"question" TEXT NOT NULL,
"position" INTEGER NOT NULL,
"randomOrder" BOOLEAN NOT NULL,
"nbPtsPositif" INTEGER NOT NULL,
"nbPtsNegatif" INTEGER NOT NULL,
"numeric" INTEGER,
"idQCM" INTEGER NOT NULL,
"idType" INTEGER NOT NULL,
"isMultiple" BOOLEAN NOT NULL,
CONSTRAINT "Question_idQCM_fkey" FOREIGN KEY ("idQCM") REFERENCES "QcmTable" ("idQCM") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Question_idType_fkey" FOREIGN KEY ("idType") REFERENCES "Type" ("idType") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Question" ("idQCM", "idQuestion", "idType", "isMultiple", "nbPtsNegatif", "nbPtsPositif", "numeric", "position", "question") SELECT "idQCM", "idQuestion", "idType", "isMultiple", "nbPtsNegatif", "nbPtsPositif", "numeric", "position", "question" FROM "Question";
DROP TABLE "Question";
ALTER TABLE "new_Question" RENAME TO "Question";
PRAGMA foreign_key_check("Question");
PRAGMA foreign_keys=ON;
-- This is an empty migration.
\ No newline at end of file
/*
Warnings:
- You are about to alter the column `numeric` on the `Question` table. The data in that column could be lost. The data in that column will be cast from `Int` to `Float`.
*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Question" (
"idQuestion" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"question" TEXT NOT NULL,
"position" INTEGER NOT NULL,
"nbPtsPositif" INTEGER NOT NULL,
"nbPtsNegatif" INTEGER NOT NULL,
"numeric" REAL,
"idQCM" INTEGER NOT NULL,
"idType" INTEGER NOT NULL,
"isMultiple" BOOLEAN NOT NULL,
CONSTRAINT "Question_idQCM_fkey" FOREIGN KEY ("idQCM") REFERENCES "QcmTable" ("idQCM") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Question_idType_fkey" FOREIGN KEY ("idType") REFERENCES "Type" ("idType") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Question" ("idQCM", "idQuestion", "idType", "isMultiple", "nbPtsNegatif", "nbPtsPositif", "numeric", "position", "question") SELECT "idQCM", "idQuestion", "idType", "isMultiple", "nbPtsNegatif", "nbPtsPositif", "numeric", "position", "question" FROM "Question";
DROP TABLE "Question";
ALTER TABLE "new_Question" RENAME TO "Question";
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
-- This is an empty migration.
\ No newline at end of file
/*
Warnings:
- Added the required column `randomOrder` to the `Question` table without a default value. This is not possible if the table is not empty.
*/
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_Question" (
"idQuestion" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"question" TEXT NOT NULL,
"position" INTEGER NOT NULL,
"randomOrder" BOOLEAN NOT NULL,
"nbPtsPositif" INTEGER NOT NULL,
"nbPtsNegatif" INTEGER NOT NULL,
"numeric" REAL,
"idQCM" INTEGER NOT NULL,
"idType" INTEGER NOT NULL,
"isMultiple" BOOLEAN NOT NULL,
CONSTRAINT "Question_idQCM_fkey" FOREIGN KEY ("idQCM") REFERENCES "QcmTable" ("idQCM") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "Question_idType_fkey" FOREIGN KEY ("idType") REFERENCES "Type" ("idType") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_Question" ("idQCM", "idQuestion", "idType", "isMultiple", "nbPtsNegatif", "nbPtsPositif", "numeric", "position", "question") SELECT "idQCM", "idQuestion", "idType", "isMultiple", "nbPtsNegatif", "nbPtsPositif", "numeric", "position", "question" FROM "Question";
DROP TABLE "Question";
ALTER TABLE "new_Question" RENAME TO "Question";
PRAGMA foreign_key_check("Question");
PRAGMA foreign_keys=ON;
# Please do not edit this file manually # Please do not edit this file manually
# It should be added in your version-control system (i.e. Git) # It should be added in your version-control system (e.g., Git)
provider = "sqlite" provider = "postgresql"
\ No newline at end of file \ No newline at end of file
...@@ -7,6 +7,7 @@ datasource db { ...@@ -7,6 +7,7 @@ datasource db {
url = env("DATABASE_URL") url = env("DATABASE_URL")
} }
// This model is not complete. It's a base for you to start working with Prisma. // This model is not complete. It's a base for you to start working with Prisma.
model User { model User {
id Int @id /// The user's id is the same as their gitlab id id Int @id /// The user's id is the same as their gitlab id
...@@ -34,7 +35,7 @@ model QcmTable { ...@@ -34,7 +35,7 @@ model QcmTable {
model Type { model Type {
idType Int @id @default(autoincrement()) idType Int @id @default(autoincrement())
nomType String nomType String @unique
questions Question[] questions Question[]
} }
......
import process from 'process'; import process from 'process';
import logger from '../src/logging/WinstonLogger.js'; import logger from '../src/logging/WinstonLogger.js';
import db from '../src/helpers/DatabaseHelper.js'; import db from '../src/helpers/DatabaseHelper.js';
import Config from '../src/config/Config.js'; import Config from '../src/config/Config.js';
async function main() { async function main() {
await users(); await users();
await types();
} }
main().then(async () => { main().then(async () => {
...@@ -20,47 +20,57 @@ main().then(async () => { ...@@ -20,47 +20,57 @@ main().then(async () => {
async function users() { async function users() {
await db.user.upsert({ await db.user.upsert({
where : { id: 142 }, where: { id: 142 },
update: { update: {
name: 'Michaël Minelli' name: 'Michaël Minelli'
}, },
create: { create: {
id : 142, id: 142,
name : 'Michaël Minelli', name: 'Michaël Minelli',
gitlabUsername: 'michael.minelli', gitlabUsername: 'michael.minelli',
deleted : false deleted: false
} }
}); });
if ( !Config.production ) { if (!Config.production) {
await db.user.upsert({ await db.user.upsert({
where : { id: 525 }, where: { id: 525 },
update: { update: {
deleted: false deleted: false
}, },
create: { create: {
id : 525, id: 525,
gitlabUsername: 'stephane.malandai', gitlabUsername: 'stephane.malandai',
deleted : false deleted: false
} }
}); });
} }
await db.type.create({ }
data: {
idType : 1, async function types() {
nomType : 'text', await db.type.upsert({
where: { nomType: 'text' },
update: {},
create: {
nomType: 'text'
} }
}); });
await db.type.create({
data: { await db.type.upsert({
idType : 2, where: { nomType: 'numerique' },
nomType : 'numerique', update: {},
create: {
nomType: 'numerique'
} }
}); });
await db.type.create({
data: { await db.type.upsert({
idType : 3, where: { nomType: 'vraiFaux' },
nomType : 'vraiFaux', update: {},
create: {
nomType: 'vraiFaux'
} }
}); });
}
\ No newline at end of file console.log("✅ Types de base insérés ou déjà présents.");
}
...@@ -18,7 +18,6 @@ services: ...@@ -18,7 +18,6 @@ services:
- ./nginx.conf:/etc/nginx/nginx.conf:ro - ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./cors.conf:/etc/nginx/cors.conf:ro - ./cors.conf:/etc/nginx/cors.conf:ro
depends_on: depends_on:
- service-helloworld
- service-auth - service-auth
- service-correction-qcm - service-correction-qcm
- service-realise-qcm - service-realise-qcm
...@@ -40,23 +39,16 @@ services: ...@@ -40,23 +39,16 @@ services:
networks: networks:
- backend_network - backend_network
service-helloworld:
image: service-helloworld
build: ./helloworld
ports:
- "8002:30992" # Expose pour les tests locaux si nécessaire
networks:
- backend_network
service-auth: service-auth:
image: service-auth image: service-auth
build: ./auth build: ./auth
ports: ports:
- "8001:30992" - "8002:30992" # Expose pour les tests locaux si nécessaire
environment:
- API_PORT=30992 # S'assurer que le service écoute sur le bon port
networks: networks:
- backend_network - backend_network
depends_on:
- service-database
service-correction-qcm: service-correction-qcm:
image: service-correction-qcm image: service-correction-qcm
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment