From 9664de0e16c42c73070cccf16467f51a7e6414ac Mon Sep 17 00:00:00 2001 From: Mostapha El Sabah Date: Fri, 20 Dec 2024 16:47:28 -0500 Subject: [PATCH 1/7] chore: improve local setup and change database type --- .env | 2 +- .gitignore | 5 ++++- devops/docker-compose.dev.yml | 9 +++++++++ devops/docker-compose.wait.yml | 3 +++ package.json | 6 ++++-- prisma/schema.prisma | 2 +- 6 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 devops/docker-compose.dev.yml create mode 100644 devops/docker-compose.wait.yml diff --git a/.env b/.env index 02ba082..fb1dccd 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" \ No newline at end of file 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..21e83c7 --- /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 \ No newline at end of file diff --git a/devops/docker-compose.wait.yml b/devops/docker-compose.wait.yml new file mode 100644 index 0000000..0c041e4 --- /dev/null +++ b/devops/docker-compose.wait.yml @@ -0,0 +1,3 @@ +services: + wait: + image: dokku/wait \ No newline at end of file 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/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") } -- 2.45.3 From fbace73c94e468e8d69c8d5828c34b14f5983103 Mon Sep 17 00:00:00 2001 From: Mostapha El Sabah Date: Fri, 20 Dec 2024 16:49:33 -0500 Subject: [PATCH 2/7] code owners bruh --- .github/workflows/CODEOWNERS | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .github/workflows/CODEOWNERS diff --git a/.github/workflows/CODEOWNERS b/.github/workflows/CODEOWNERS new file mode 100644 index 0000000..9fa5be3 --- /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@Baobeld@DanMihailescu \ No newline at end of file -- 2.45.3 From e0f3613422f2e4bc13da8c0d282b94f6e6418139 Mon Sep 17 00:00:00 2001 From: Mostapha El Sabah Date: Fri, 20 Dec 2024 16:50:29 -0500 Subject: [PATCH 3/7] yo --- .env | 2 +- devops/docker-compose.dev.yml | 3 ++- devops/docker-compose.wait.yml | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.env b/.env index fb1dccd..ac58967 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ VITE_APP_VERSION=1.0.0-alpha -DATABASE_URL="postgres://hestia:test123@localhost:5432/hestia" \ No newline at end of file +DATABASE_URL="postgres://hestia:test123@localhost:5432/hestia" diff --git a/devops/docker-compose.dev.yml b/devops/docker-compose.dev.yml index 21e83c7..e09c787 100644 --- a/devops/docker-compose.dev.yml +++ b/devops/docker-compose.dev.yml @@ -6,4 +6,5 @@ services: - '5432:5432' environment: POSTGRES_USER: hestia - POSTGRES_PASSWORD: test123 \ No newline at end of file + POSTGRES_PASSWORD: test123 + \ No newline at end of file diff --git a/devops/docker-compose.wait.yml b/devops/docker-compose.wait.yml index 0c041e4..7eb2dc4 100644 --- a/devops/docker-compose.wait.yml +++ b/devops/docker-compose.wait.yml @@ -1,3 +1,4 @@ services: wait: - image: dokku/wait \ No newline at end of file + image: dokku/wait + \ No newline at end of file -- 2.45.3 From 68650e922cbc93ff69f7df0a474619c51b34a731 Mon Sep 17 00:00:00 2001 From: Mostapha El Sabah Date: Fri, 20 Dec 2024 16:53:33 -0500 Subject: [PATCH 4/7] migrate the db --- .github/workflows/CODEOWNERS | 2 +- .../20241220011159_init/migration.sql | 34 -------------- .../migration.sql | 44 +++++++++++++++++++ prisma/migrations/migration_lock.toml | 2 +- 4 files changed, 46 insertions(+), 36 deletions(-) delete mode 100644 prisma/migrations/20241220011159_init/migration.sql create mode 100644 prisma/migrations/20241220215308_initial_migration/migration.sql diff --git a/.github/workflows/CODEOWNERS b/.github/workflows/CODEOWNERS index 9fa5be3..5863b7e 100644 --- a/.github/workflows/CODEOWNERS +++ b/.github/workflows/CODEOWNERS @@ -2,4 +2,4 @@ # These owners will be the default owners for everything in # the repo. Unless a later match takes precedence, -* @piopi@Baobeld@DanMihailescu \ No newline at end of file +* @piopi@Baobeld@DanMihailescu 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 -- 2.45.3 From d77e4aa2edab2938f485ce79676d8c3877e38b43 Mon Sep 17 00:00:00 2001 From: Mostapha El Sabah Date: Fri, 20 Dec 2024 16:54:16 -0500 Subject: [PATCH 5/7] ww --- .github/workflows/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CODEOWNERS b/.github/workflows/CODEOWNERS index 5863b7e..feb917e 100644 --- a/.github/workflows/CODEOWNERS +++ b/.github/workflows/CODEOWNERS @@ -2,4 +2,4 @@ # These owners will be the default owners for everything in # the repo. Unless a later match takes precedence, -* @piopi@Baobeld@DanMihailescu +* @piopi @Baobeld @DanMihailescu -- 2.45.3 From 540c3f8e5ddd198713db6d81a2e62e5ababd4622 Mon Sep 17 00:00:00 2001 From: Mostapha El Sabah Date: Fri, 20 Dec 2024 17:11:01 -0500 Subject: [PATCH 6/7] wqwq --- devops/docker-compose.dev.yml | 17 ++++++++--------- devops/docker-compose.wait.yml | 5 ++--- src/lib/server/auth/index.ts | 2 +- src/routes/+page.server.ts | 2 +- src/routes/app/+layout.server.ts | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/devops/docker-compose.dev.yml b/devops/docker-compose.dev.yml index e09c787..d0f9410 100644 --- a/devops/docker-compose.dev.yml +++ b/devops/docker-compose.dev.yml @@ -1,10 +1,9 @@ services: - hestia-database: - image: 'postgres:12-alpine' - container_name: 'hestia-database' - ports: - - '5432:5432' - environment: - POSTGRES_USER: hestia - POSTGRES_PASSWORD: test123 - \ No newline at end of file + 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 index 7eb2dc4..f334a81 100644 --- a/devops/docker-compose.wait.yml +++ b/devops/docker-compose.wait.yml @@ -1,4 +1,3 @@ services: - wait: - image: dokku/wait - \ No newline at end of file + wait: + image: dokku/wait diff --git a/src/lib/server/auth/index.ts b/src/lib/server/auth/index.ts index 339c850..280c94c 100644 --- a/src/lib/server/auth/index.ts +++ b/src/lib/server/auth/index.ts @@ -19,4 +19,4 @@ export async function validateSession(event: ServerLoadEvent) { redirect(302, '/login'); } return session; -} \ No newline at end of file +} diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index bff4064..5d81608 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -2,4 +2,4 @@ import { validateSession } from '$lib/server/auth'; export async function load(event) { await validateSession(event); -} \ No newline at end of file +} diff --git a/src/routes/app/+layout.server.ts b/src/routes/app/+layout.server.ts index b831d3e..894e1f4 100644 --- a/src/routes/app/+layout.server.ts +++ b/src/routes/app/+layout.server.ts @@ -7,4 +7,4 @@ export async function load(event) { return { user: rest, }; -} \ No newline at end of file +} -- 2.45.3 From e64ba7484235e22d4f70879cf4fd87f8f4511a1b Mon Sep 17 00:00:00 2001 From: Mostapha El Sabah Date: Fri, 20 Dec 2024 17:16:16 -0500 Subject: [PATCH 7/7] ba --- .github/workflows/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CODEOWNERS b/.github/workflows/CODEOWNERS index feb917e..e830842 100644 --- a/.github/workflows/CODEOWNERS +++ b/.github/workflows/CODEOWNERS @@ -2,4 +2,4 @@ # These owners will be the default owners for everything in # the repo. Unless a later match takes precedence, -* @piopi @Baobeld @DanMihailescu +* @piopi @BenjaminPalko @DanMihailescu -- 2.45.3