Skip to content

Commit

Permalink
feat: 🗃️ add initial migration
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashbrnrd committed Dec 6, 2024
1 parent bc38ac6 commit 0be70f4
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 495 deletions.
33 changes: 13 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,29 @@ Fournir un point de vérité pour répertorier, catégoriser et gérer les méta
Liste des outils utilisés par le projet à installer :

- [Docker](https://docs.docker.com/get-started/get-docker/)
- [NodeJs](https://nodejs.org/en/download/package-manager)

### Étapes d'Installation
### How to run ?

1. **Installer les dépendances**
1. Run the stack

```bash
pnpm install
```

2. **Configurer les variables d'environnement**
```bash
cp .env.example .env
# Modifier le fichier .env selon vos besoins
```

### Démarrage de l'API

> L'API sera accessible a l'adresse [http://localhost:3500](http://localhost:3500/)
```bash
docker compose up -d
```

> Le swagger de l'API sera accessible a l'adresse [http://localhost:3500/api/v2]()
2. Run migrations (in the backend container)

```bash
pnpm run docker:start
npx prisma migrate deploy
```

### Arret de l'API
### How to stop ?

```bash
pnpm run docker:stop
docker compose down
```

### More

See [docker-compose.yml](docker-compose.yml) for services definitions.

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
backend:
build:
context: ./server
command: pnpm run start:dev
command: pnpm start:dev
environment:
- DATABASE_URL=postgresql://postgres:password@postgres:5432/postgres
- ALLOWED_ORIGINS=http://localhost:5173,http://localhost:8080,http://krakend:8080
Expand All @@ -31,6 +31,7 @@ services:
- "3500:3500"
volumes:
- ./server:/app
- /app/node_modules

keycloak:
build:
Expand Down
2 changes: 1 addition & 1 deletion server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ COPY . .

# Install application dependencies
RUN npm install -g pnpm
RUN pnpm install
RUN pnpm install --frozen-lockfile
RUN npx prisma generate

# Define the port on which the NestJS application is listening
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev": "cross-env NODE_ENV=development nest start --watch",
"build": "nest build",
"start": "nest start",
"start:dev": "npx prisma db push && cross-env NODE_ENV=development nest start --watch",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
Expand Down
479 changes: 8 additions & 471 deletions server/pnpm-lock.yaml

Large diffs are not rendered by default.

190 changes: 190 additions & 0 deletions server/prisma/migrations/20241206153840_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
-- CreateEnum
CREATE TYPE "ComplianceType" AS ENUM ('regulation', 'standard', 'policy', 'contractual', 'security', 'privacy');

-- CreateEnum
CREATE TYPE "ComplianceStatus" AS ENUM ('compliant', 'non_compliant', 'partially_compliant', 'not_concerned');

-- CreateEnum
CREATE TYPE "ExternalSourceType" AS ENUM ('organization', 'application', 'regulation', 'financial', 'population');

-- CreateEnum
CREATE TYPE "ExternalSourceValueType" AS ENUM ('url', 'uri', 'identifier', 'name');

-- CreateEnum
CREATE TYPE "LifecycleStatus" AS ENUM ('under_construction', 'in_production', 'decommissioned', 'retired_from_service');

-- CreateTable
CREATE TABLE "applications" (
"id" TEXT NOT NULL,
"label" TEXT NOT NULL,
"shortName" TEXT,
"logo" TEXT,
"description" TEXT NOT NULL,
"url" TEXT NOT NULL,
"uri" TEXT NOT NULL,
"purposes" TEXT[],
"tags" TEXT[],
"lifecycleId" TEXT NOT NULL,
"metadataId" TEXT NOT NULL,
"parentId" TEXT,
"ownerId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "compliances" (
"id" TEXT NOT NULL,
"type" "ComplianceType" NOT NULL,
"name" TEXT NOT NULL,
"status" "ComplianceStatus" NOT NULL,
"validityStart" TIMESTAMP(3),
"validityEnd" TIMESTAMP(3),
"scoreValue" TEXT,
"scoreUnit" TEXT,
"notes" TEXT,
"metadataId" TEXT,
"applicationId" TEXT,

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

-- CreateTable
CREATE TABLE "externals" (
"id" TEXT NOT NULL,
"externalSourceId" TEXT NOT NULL,
"value" TEXT NOT NULL,
"label" TEXT NOT NULL,
"shortName" TEXT,
"lastSourceUpdate" TIMESTAMP(3) NOT NULL,
"metadataId" TEXT NOT NULL,
"applicationId" TEXT,

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

-- CreateTable
CREATE TABLE "externalSources" (
"id" TEXT NOT NULL,
"type" "ExternalSourceType" NOT NULL,
"uri" TEXT NOT NULL,
"valueType" "ExternalSourceValueType" NOT NULL,
"metadataId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "lifecycles" (
"id" TEXT NOT NULL,
"status" "LifecycleStatus" NOT NULL,
"firstProductionDate" TIMESTAMP(3),
"plannedDecommissioningDate" TIMESTAMP(3),
"metadataId" TEXT NOT NULL,

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

-- CreateTable
CREATE TABLE "metadata" (
"id" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
"createdById" TEXT NOT NULL,
"updatedById" TEXT NOT NULL,
"dataOwnerId" TEXT,

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

-- CreateTable
CREATE TABLE "users" (
"keycloakId" TEXT NOT NULL,
"email" TEXT NOT NULL,
"organizationId" TEXT,

CONSTRAINT "users_pkey" PRIMARY KEY ("keycloakId")
);

-- CreateTable
CREATE TABLE "actors" (
"id" TEXT NOT NULL,
"role" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"organizationId" TEXT,
"applicationId" TEXT,

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

-- CreateIndex
CREATE INDEX "applications_label_idx" ON "applications"("label");

-- CreateIndex
CREATE INDEX "applications_shortName_idx" ON "applications"("shortName");

-- CreateIndex
CREATE UNIQUE INDEX "externalSources_uri_key" ON "externalSources"("uri");

-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");

-- CreateIndex
CREATE INDEX "actors_userId_idx" ON "actors"("userId");

-- CreateIndex
CREATE INDEX "actors_applicationId_idx" ON "actors"("applicationId");

-- AddForeignKey
ALTER TABLE "applications" ADD CONSTRAINT "applications_lifecycleId_fkey" FOREIGN KEY ("lifecycleId") REFERENCES "lifecycles"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "applications" ADD CONSTRAINT "applications_metadataId_fkey" FOREIGN KEY ("metadataId") REFERENCES "metadata"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "applications" ADD CONSTRAINT "applications_parentId_fkey" FOREIGN KEY ("parentId") REFERENCES "applications"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "applications" ADD CONSTRAINT "applications_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "users"("keycloakId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "compliances" ADD CONSTRAINT "compliances_metadataId_fkey" FOREIGN KEY ("metadataId") REFERENCES "metadata"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "compliances" ADD CONSTRAINT "compliances_applicationId_fkey" FOREIGN KEY ("applicationId") REFERENCES "applications"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "externals" ADD CONSTRAINT "externals_externalSourceId_fkey" FOREIGN KEY ("externalSourceId") REFERENCES "externalSources"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "externals" ADD CONSTRAINT "externals_metadataId_fkey" FOREIGN KEY ("metadataId") REFERENCES "metadata"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "externals" ADD CONSTRAINT "externals_applicationId_fkey" FOREIGN KEY ("applicationId") REFERENCES "applications"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "externalSources" ADD CONSTRAINT "externalSources_metadataId_fkey" FOREIGN KEY ("metadataId") REFERENCES "metadata"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "lifecycles" ADD CONSTRAINT "lifecycles_metadataId_fkey" FOREIGN KEY ("metadataId") REFERENCES "metadata"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "metadata" ADD CONSTRAINT "metadata_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "users"("keycloakId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "metadata" ADD CONSTRAINT "metadata_updatedById_fkey" FOREIGN KEY ("updatedById") REFERENCES "users"("keycloakId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "metadata" ADD CONSTRAINT "metadata_dataOwnerId_fkey" FOREIGN KEY ("dataOwnerId") REFERENCES "users"("keycloakId") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "users" ADD CONSTRAINT "users_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "externals"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "actors" ADD CONSTRAINT "actors_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("keycloakId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "actors" ADD CONSTRAINT "actors_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "externals"("id") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "actors" ADD CONSTRAINT "actors_applicationId_fkey" FOREIGN KEY ("applicationId") REFERENCES "applications"("id") ON DELETE SET NULL ON UPDATE CASCADE;
3 changes: 3 additions & 0 deletions server/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion server/prisma/schema/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions", "fullTextSearch", "fullTextIndex", "driverAdapters", "prismaSchemaFolder"]
binaryTargets = ["native", "debian-openssl-1.1.x"]
binaryTargets = ["native"]
}

datasource db {
Expand Down

0 comments on commit 0be70f4

Please sign in to comment.