From 448a2ae1bfd3bdf5b63a16f0f1eac756ce896986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henry=20Gr=C3=A6sberg?= Date: Sun, 25 Oct 2026 22:06:07 +0100 Subject: [PATCH 1/4] Bump to postgres 18 --- docker-compose.yml | 2 +- scripts/setup-db.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 64d4da1..b7584f2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ services: db: container_name: g_spotter_db - image: postgres:16-alpine@sha256:b7587f3cb74f4f4b2a4f9d67f052edbf95eb93f4fec7c5ada3792546caaf7383 + image: postgres:18-alpine@sha256:898c60cb390d1085bc97bdd6a1ae968757421df394b071848b52b1c09c89d6a5 restart: always environment: POSTGRES_PASSWORD: gspotter diff --git a/scripts/setup-db.sh b/scripts/setup-db.sh index 7805307..6fb7b45 100755 --- a/scripts/setup-db.sh +++ b/scripts/setup-db.sh @@ -21,7 +21,7 @@ fi apt-get update -y -if ! apt-get install -y postgresql-16; then +if ! apt-get install -y postgresql-18; then apt-get install -y postgresql fi From a24e0b43b15cd562cebe9f885f875f209ec5d0e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henry=20Gr=C3=A6sberg?= Date: Sun, 25 Oct 2026 22:15:10 +0100 Subject: [PATCH 2/4] Update uuid's to v7 and remove unnecessary dates from times of day Update ids to use UUIDv7 to improve database indexing, as v7 combines a 48 bit timestamp and random bits to aid in database indexing Update opening hours and limitation time ranges to use only timetz as having a date in the rows was unnecessary --- .../migration.sql | 15 +++++ packages/db/prisma/schema.prisma | 60 +++++++++---------- 2 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 packages/db/prisma/migrations/20261025211749_update_uuids_to_v7_and_remove_unnecessary_dates/migration.sql diff --git a/packages/db/prisma/migrations/20261025211749_update_uuids_to_v7_and_remove_unnecessary_dates/migration.sql b/packages/db/prisma/migrations/20261025211749_update_uuids_to_v7_and_remove_unnecessary_dates/migration.sql new file mode 100644 index 0000000..ba7e32d --- /dev/null +++ b/packages/db/prisma/migrations/20261025211749_update_uuids_to_v7_and_remove_unnecessary_dates/migration.sql @@ -0,0 +1,15 @@ +-- AlterTable +ALTER TABLE "city" ALTER COLUMN "id" SET DEFAULT uuidv7(); + +-- AlterTable +ALTER TABLE "opening_hours" ALTER COLUMN "id" SET DEFAULT uuidv7(), +ALTER COLUMN "opening" SET DATA TYPE TIMETZ, +ALTER COLUMN "closing" SET DATA TYPE TIMETZ; + +-- AlterTable +ALTER TABLE "price_sighting" ALTER COLUMN "id" SET DEFAULT uuidv7(), +ALTER COLUMN "time_start" SET DATA TYPE TIMETZ, +ALTER COLUMN "time_end" SET DATA TYPE TIMETZ; + +-- AlterTable +ALTER TABLE "venue" ALTER COLUMN "id" SET DEFAULT uuidv7(); diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma index 914b1db..f9b09c3 100644 --- a/packages/db/prisma/schema.prisma +++ b/packages/db/prisma/schema.prisma @@ -14,17 +14,17 @@ datasource db { } enum GlassSize { - PINT @map("PINT") - HALF_LITER @map("HALF_LITER") + PINT @map("PINT") + HALF_LITER @map("HALF_LITER") QUARTER_LITER @map("QUARTER_LITER") - BOX @map("BOX") - OTHER @map("OTHER") + BOX @map("BOX") + OTHER @map("OTHER") @@map("glass_size") } enum Limitations { - TIME @map("TIME") + TIME @map("TIME") MEMBERSHIP @map("MEMBERSHIP") @@map("limitations") @@ -43,14 +43,14 @@ enum Day { } model Venue { - id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String + id String @id @default(dbgenerated("uuidv7()")) @db.Uuid + name String address String openingHours OpeningHours[] - cityId String @db.Uuid @map("city_id") - city City @relation(fields: [cityId], references: [id]) + cityId String @map("city_id") @db.Uuid + city City @relation(fields: [cityId], references: [id]) pricesSighted PriceSighting[] @@ -58,22 +58,22 @@ model Venue { } model OpeningHours { - id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid - days Day[] - opening DateTime @db.Timestamptz() - closing DateTime @db.Timestamptz() + id String @id @default(dbgenerated("uuidv7()")) @db.Uuid + days Day[] + opening DateTime @db.Timetz() + closing DateTime @db.Timetz() - venueId String @db.Uuid @map("venue_id") - venue Venue @relation(fields: [venueId], references: [id]) + venueId String @map("venue_id") @db.Uuid + venue Venue @relation(fields: [venueId], references: [id]) @@map("opening_hours") } model City { - id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid - name String - centreLon Float @map("centre_lon") - centreLat Float @map("centre_lat") + id String @id @default(dbgenerated("uuidv7()")) @db.Uuid + name String + centreLon Float @map("centre_lon") + centreLat Float @map("centre_lat") venues Venue[] @@ -81,17 +81,17 @@ model City { } model PriceSighting { - id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid - price Float - size GlassSize - limitation Limitations[] - timeStart DateTime? @db.Timestamptz() @map("time_start") - timeEnd DateTime? @db.Timestamptz() @map("time_end") - sizeMl Float? @map("size_ml") - timeSighted DateTime @db.Timestamptz() @map("time_sighted") - - venueId String @db.Uuid @map("venue_id") - venue Venue @relation(fields: [venueId], references: [id]) + id String @id @default(dbgenerated("uuidv7()")) @db.Uuid + price Float + size GlassSize + limitation Limitations[] + timeStart DateTime? @map("time_start") @db.Timetz() + timeEnd DateTime? @map("time_end") @db.Timetz() + sizeMl Float? @map("size_ml") + timeSighted DateTime @map("time_sighted") @db.Timestamptz() + + venueId String @map("venue_id") @db.Uuid + venue Venue @relation(fields: [venueId], references: [id]) @@map("price_sighting") } From 14f19d8424e81a88387620825fd13425534248f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henry=20Gr=C3=A6sberg?= Date: Sun, 25 Oct 2026 22:47:53 +0100 Subject: [PATCH 3/4] Temporarily make deployment run manually to give time to update prod postgres This is to prevent a scenario where a database migration is attempted before postgres is updated from 16 to 18, as "uuidv7()" was introduced with postgres 18 - the command would simply fail and the database would keep running, but this would mean the generated types would be mismatched with the actual database scema --- .github/workflows/deploy-to-vm.yaml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-to-vm.yaml b/.github/workflows/deploy-to-vm.yaml index b0d34ba..f7d2eca 100644 --- a/.github/workflows/deploy-to-vm.yaml +++ b/.github/workflows/deploy-to-vm.yaml @@ -25,12 +25,7 @@ name: CI/CD - Deploy to VM -on: - workflow_run: - workflows: ['CI/CD - Linter, formatter and tests'] - types: [completed] - branches: - - main +on: workflow_dispatch permissions: contents: read @@ -79,6 +74,9 @@ jobs: printf 'DATABASE_URL="%s"\n' "$DATABASE_URL" > apps/backend/.env cp apps/backend/.env packages/db/.env + - name: Apply database migrations + run: pnpm --filter @t09-project-2/db run db:push + - name: Generate Prisma client run: pnpm --filter @t09-project-2/db run db:generate From add46c95e32280e799da8f19dd51d7ca3190615e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henry=20Gr=C3=A6sberg?= Date: Tue, 27 Oct 2026 09:31:35 +0100 Subject: [PATCH 4/4] Add hand in 2 commit hash to readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3cbbd9d..189d0d1 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ Most recent commit hash at time of hand-in: [`efdbfa5`](https://git.ntnu.no/IT28 Handed in Oct 16th -Most recent commit hash at time of hand-in: [`TDB`](<>) (Will update if there is a more recent version in the future) +Most recent commit hash at time of hand-in: [`054801b`](https://git.ntnu.no/IT2810-H26/T09-Project-2/tree/054801b7b8058fe35a5303cd54ff7815cbac0be8) ### 3rd hand-in of project 2