From 3501a487356e97086cda0c8a15cc0195a0587520 Mon Sep 17 00:00:00 2001 From: alexis-moins Date: Mon, 20 Nov 2023 13:53:38 +0100 Subject: [PATCH] fix(backend.yaml): wait for services to be healthy --- .env.local | 12 ++--- .github/workflows/backend.yaml | 5 +- back/entrypoint.sh | 2 +- .../20231113135109_create_user/migration.sql | 9 ---- .../migration.sql | 50 ------------------- .../migration.sql | 46 +++++++++++++++++ back/prisma/migrations/migration_lock.toml | 2 +- back/prisma/schema.prisma | 2 +- docker-compose.yaml | 16 +++--- 9 files changed, 62 insertions(+), 82 deletions(-) delete mode 100644 back/prisma/migrations/20231113135109_create_user/migration.sql delete mode 100644 back/prisma/migrations/20231113152055_add_lucia_auth/migration.sql create mode 100644 back/prisma/migrations/20231120134558_initial_migration/migration.sql diff --git a/.env.local b/.env.local index 4cf96d5..cbee523 100644 --- a/.env.local +++ b/.env.local @@ -5,11 +5,9 @@ FRONTEND_PORT=3000 ADMINER_PORT=8080 ADMINER_DESIGN=lucas-sandery -MYSQL_ROOT_PASSWORD=root +POSTGRES_USER=john +POSTGRES_PASSWORD=doe -MYSQL_USER=john -MYSQL_PASSWORD=doe - -# Needs root privileges to manage DB -DATABASE_URL=mysql://root:root@database:3306/count_of_money -TEST_DATABASE_URL=mysql://root:root@database:3306/count_of_money_test +# Note: change user:password to match the fields above! +DATABASE_URL=postgresql://john:doe@database:5432/count_of_money?schema=public +TEST_DATABASE_URL=postgresql://john:doe@database:5432/count_of_money_test?schema=public diff --git a/.github/workflows/backend.yaml b/.github/workflows/backend.yaml index 10aaf92..400391c 100644 --- a/.github/workflows/backend.yaml +++ b/.github/workflows/backend.yaml @@ -17,8 +17,5 @@ jobs: - name: Set environment variables run: cp .env.local .env - - name: Build test docker image - run: docker compose build --no-cache test - - name: Start tests - run: docker-compose up database test + run: docker compose up database test diff --git a/back/entrypoint.sh b/back/entrypoint.sh index 9e475fc..6857892 100755 --- a/back/entrypoint.sh +++ b/back/entrypoint.sh @@ -3,6 +3,6 @@ set -ex npx prisma generate -npx prisma migrate dev +npx prisma migrate deploy npm run dev diff --git a/back/prisma/migrations/20231113135109_create_user/migration.sql b/back/prisma/migrations/20231113135109_create_user/migration.sql deleted file mode 100644 index ba4dbbd..0000000 --- a/back/prisma/migrations/20231113135109_create_user/migration.sql +++ /dev/null @@ -1,9 +0,0 @@ --- CreateTable -CREATE TABLE `User` ( - `id` INTEGER NOT NULL AUTO_INCREMENT, - `email` VARCHAR(191) NOT NULL, - `password` VARCHAR(191) NOT NULL, - - UNIQUE INDEX `User_email_key`(`email`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; diff --git a/back/prisma/migrations/20231113152055_add_lucia_auth/migration.sql b/back/prisma/migrations/20231113152055_add_lucia_auth/migration.sql deleted file mode 100644 index 61e7c8f..0000000 --- a/back/prisma/migrations/20231113152055_add_lucia_auth/migration.sql +++ /dev/null @@ -1,50 +0,0 @@ -/* - Warnings: - - - The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint. - - You are about to drop the column `email` on the `User` table. All the data in the column will be lost. - - You are about to drop the column `password` on the `User` table. All the data in the column will be lost. - - A unique constraint covering the columns `[id]` on the table `User` will be added. If there are existing duplicate values, this will fail. - -*/ --- DropIndex -DROP INDEX `User_email_key` ON `User`; - --- AlterTable -ALTER TABLE `User` DROP PRIMARY KEY, - DROP COLUMN `email`, - DROP COLUMN `password`, - MODIFY `id` VARCHAR(191) NOT NULL, - ADD PRIMARY KEY (`id`); - --- CreateTable -CREATE TABLE `Session` ( - `id` VARCHAR(191) NOT NULL, - `user_id` VARCHAR(191) NOT NULL, - `active_expires` BIGINT NOT NULL, - `idle_expires` BIGINT NOT NULL, - - UNIQUE INDEX `Session_id_key`(`id`), - INDEX `Session_user_id_idx`(`user_id`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateTable -CREATE TABLE `Key` ( - `id` VARCHAR(191) NOT NULL, - `hashed_password` VARCHAR(191) NULL, - `user_id` VARCHAR(191) NOT NULL, - - UNIQUE INDEX `Key_id_key`(`id`), - INDEX `Key_user_id_idx`(`user_id`), - PRIMARY KEY (`id`) -) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; - --- CreateIndex -CREATE UNIQUE INDEX `User_id_key` ON `User`(`id`); - --- AddForeignKey -ALTER TABLE `Session` ADD CONSTRAINT `Session_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE `Key` ADD CONSTRAINT `Key_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/back/prisma/migrations/20231120134558_initial_migration/migration.sql b/back/prisma/migrations/20231120134558_initial_migration/migration.sql new file mode 100644 index 0000000..7ea9523 --- /dev/null +++ b/back/prisma/migrations/20231120134558_initial_migration/migration.sql @@ -0,0 +1,46 @@ +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Session" ( + "id" TEXT NOT NULL, + "user_id" TEXT NOT NULL, + "active_expires" BIGINT NOT NULL, + "idle_expires" BIGINT NOT NULL, + + CONSTRAINT "Session_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Key" ( + "id" TEXT NOT NULL, + "hashed_password" TEXT, + "user_id" TEXT NOT NULL, + + CONSTRAINT "Key_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_id_key" ON "User"("id"); + +-- CreateIndex +CREATE UNIQUE INDEX "Session_id_key" ON "Session"("id"); + +-- CreateIndex +CREATE INDEX "Session_user_id_idx" ON "Session"("user_id"); + +-- CreateIndex +CREATE UNIQUE INDEX "Key_id_key" ON "Key"("id"); + +-- CreateIndex +CREATE INDEX "Key_user_id_idx" ON "Key"("user_id"); + +-- AddForeignKey +ALTER TABLE "Session" ADD CONSTRAINT "Session_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Key" ADD CONSTRAINT "Key_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/back/prisma/migrations/migration_lock.toml b/back/prisma/migrations/migration_lock.toml index e5a788a..fbffa92 100644 --- a/back/prisma/migrations/migration_lock.toml +++ b/back/prisma/migrations/migration_lock.toml @@ -1,3 +1,3 @@ # Please do not edit this file manually # It should be added in your version-control system (i.e. Git) -provider = "mysql" \ No newline at end of file +provider = "postgresql" \ No newline at end of file diff --git a/back/prisma/schema.prisma b/back/prisma/schema.prisma index 73e7324..c6f22e5 100644 --- a/back/prisma/schema.prisma +++ b/back/prisma/schema.prisma @@ -3,7 +3,7 @@ generator client { } datasource db { - provider = "mysql" + provider = "postgresql" url = env("DATABASE_URL") } diff --git a/docker-compose.yaml b/docker-compose.yaml index e7a1673..1edd49a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -19,7 +19,7 @@ services: - ./back/package.json:/app/package.json depends_on: - - database + - database test: build: ./back @@ -36,7 +36,7 @@ services: - ./back/package.json:/app/package.json depends_on: - - database + - database adminer: image: adminer @@ -54,20 +54,18 @@ services: - database:db database: - image: mysql:8.0 + image: postgres:16-alpine container_name: database restart: always environment: - MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} - MYSQL_DATABASE: count_of_money - - MYSQL_USER: ${MYSQL_USER} - MYSQL_PASSWORD: ${MYSQL_PASSWORD} + POSTGRES_DB: count_of_money + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} volumes: - - database-data:/var/lib/mysql + - database-data:/var/lib/postgresql/data volumes: database-data: