From 3f9d4f94ff315cb5ebc4762ebcbccd6ced7771b4 Mon Sep 17 00:00:00 2001 From: Mostapha El Sabah Date: Fri, 20 Dec 2024 17:27:59 -0500 Subject: [PATCH] chore: improve local setup and change database type (#33) --- .env | 2 +- .github/workflows/CODEOWNERS | 5 +++ .gitignore | 5 ++- devops/docker-compose.dev.yml | 9 ++++ devops/docker-compose.wait.yml | 3 ++ package.json | 6 ++- .../20241220011159_init/migration.sql | 34 -------------- .../migration.sql | 44 +++++++++++++++++++ prisma/migrations/migration_lock.toml | 2 +- prisma/schema.prisma | 2 +- 10 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/CODEOWNERS create mode 100644 devops/docker-compose.dev.yml create mode 100644 devops/docker-compose.wait.yml delete mode 100644 prisma/migrations/20241220011159_init/migration.sql create mode 100644 prisma/migrations/20241220215308_initial_migration/migration.sql diff --git a/.env b/.env index 02ba082..ac58967 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ VITE_APP_VERSION=1.0.0-alpha -DATABASE_URL="file:./dev.db" \ No newline at end of file +DATABASE_URL="postgres://hestia:test123@localhost:5432/hestia" diff --git a/.github/workflows/CODEOWNERS b/.github/workflows/CODEOWNERS new file mode 100644 index 0000000..e830842 --- /dev/null +++ b/.github/workflows/CODEOWNERS @@ -0,0 +1,5 @@ +# See https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners + +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, +* @piopi @BenjaminPalko @DanMihailescu diff --git a/.gitignore b/.gitignore index cbf6a49..8c331d8 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,7 @@ vite.config.js.timestamp-* vite.config.ts.timestamp-* */dev.db -*/dev.db-journal \ No newline at end of file +*/dev.db-journal + +# Env files +.env.* \ No newline at end of file diff --git a/devops/docker-compose.dev.yml b/devops/docker-compose.dev.yml new file mode 100644 index 0000000..d0f9410 --- /dev/null +++ b/devops/docker-compose.dev.yml @@ -0,0 +1,9 @@ +services: + hestia-database: + image: 'postgres:12-alpine' + container_name: 'hestia-database' + ports: + - '5432:5432' + environment: + POSTGRES_USER: hestia + POSTGRES_PASSWORD: test123 diff --git a/devops/docker-compose.wait.yml b/devops/docker-compose.wait.yml new file mode 100644 index 0000000..f334a81 --- /dev/null +++ b/devops/docker-compose.wait.yml @@ -0,0 +1,3 @@ +services: + wait: + image: dokku/wait diff --git a/package.json b/package.json index 6f5af34..e026e0e 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,11 @@ "version": "0.0.1", "type": "module", "scripts": { - "dev": "vite dev", + "dev": "bun database:up && bun prisma:push && vite dev", "build": "vite build", + "build-storybook": "storybook build", + "database:up": "docker compose -p hestia -f devops/docker-compose.dev.yml up -d && docker compose -p hestia -f devops/docker-compose.dev.yml -f devops/docker-compose.wait.yml run --rm wait -c hestia-database:5432", + "database:down": "docker compose -p hestia -f devops/docker-compose.dev.yml down", "preview": "vite preview", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", @@ -13,7 +16,6 @@ "test:unit": "vitest", "test": "bun run test:unit -- --run && bun run test:e2e", "storybook": "storybook dev -p 6006", - "build-storybook": "storybook build", "test:e2e": "playwright test", "prisma:dev": "prisma migrate dev", "prisma:format": "prisma format", diff --git a/prisma/migrations/20241220011159_init/migration.sql b/prisma/migrations/20241220011159_init/migration.sql deleted file mode 100644 index bbed9b9..0000000 --- a/prisma/migrations/20241220011159_init/migration.sql +++ /dev/null @@ -1,34 +0,0 @@ --- CreateTable -CREATE TABLE "User" ( - "id" TEXT NOT NULL PRIMARY KEY, - "email" TEXT, - "name" TEXT NOT NULL, - "password" TEXT NOT NULL, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP -); - --- CreateTable -CREATE TABLE "Session" ( - "id" TEXT NOT NULL PRIMARY KEY, - "expiresAt" DATETIME NOT NULL, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "userId" TEXT NOT NULL, - CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateTable -CREATE TABLE "Post" ( - "id" TEXT NOT NULL PRIMARY KEY, - "title" TEXT NOT NULL, - "content" TEXT NOT NULL, - "published" BOOLEAN DEFAULT false, - "authorId" TEXT NOT NULL, - "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updatedAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE -); - --- CreateIndex -CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); diff --git a/prisma/migrations/20241220215308_initial_migration/migration.sql b/prisma/migrations/20241220215308_initial_migration/migration.sql new file mode 100644 index 0000000..1b5be68 --- /dev/null +++ b/prisma/migrations/20241220215308_initial_migration/migration.sql @@ -0,0 +1,44 @@ +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL, + "email" TEXT, + "name" TEXT NOT NULL, + "password" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Session" ( + "id" TEXT NOT NULL, + "expiresAt" TIMESTAMP(3) NOT NULL, + "userId" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Session_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Post" ( + "id" TEXT NOT NULL, + "title" TEXT NOT NULL, + "content" TEXT NOT NULL, + "published" BOOLEAN DEFAULT false, + "authorId" TEXT NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Post_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- AddForeignKey +ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml index e5e5c47..fbffa92 100644 --- a/prisma/migrations/migration_lock.toml +++ b/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 = "sqlite" \ No newline at end of file +provider = "postgresql" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4449dae..a23c87a 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -10,7 +10,7 @@ generator pothos { } datasource db { - provider = "sqlite" + provider = "postgresql" url = env("DATABASE_URL") }