Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package-lock.json
pnpm-lock.yaml
yarn.lock
.tanstack
.agents
**/src/generated/
86 changes: 81 additions & 5 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,84 @@ datasource db {
provider = "postgresql"
}

model Todo {
id Int @id @default(autoincrement())
title String
createdAt DateTime @default(now())
}
enum GlassSize {
PINT @map("PINT")
HALF_LITER @map("HALF_LITER")
QUARTER_LITER @map("QUARTER_LITER")
BOX @map("BOX")
OTHER @map("OTHER")
@@map("glass_size")
}

enum Limitations {
TIME @map("TIME")
MEMBERSHIP @map("MEMBERSHIP")
@@map("limitations")
}

enum Day {
MON @map("MON")
TUE @map("TUE")
WED @map("WED")
THU @map("THU")
FRI @map("FRI")
SAT @map("SAT")
SUN @map("SUN")
@@map("day")
}

model Venue {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String
address String
openingHours OpeningHours[]
cityId String @db.Uuid @map("city_id")
city City @relation(fields: [cityId], references: [id])
pricesSighted PriceSighting[]
@@map("venue")
}

model OpeningHours {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
days Day[]
opening DateTime @db.Timestamptz()
closing DateTime @db.Timestamptz()
venueId String @db.Uuid @map("venue_id")
venues Venue @relation(fields: [venueId], references: [id])
@@map("opening_hours")
}

model City {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String
centreLon String @map("centre_lon")
centreLat String @map("centre_lat")
venues Venue[]
@@map("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")
venueId String @db.Uuid @map("venue_id")
venue Venue @relation(fields: [venueId], references: [id])
@@map("price_sighting")
}
250 changes: 242 additions & 8 deletions packages/db/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,253 @@
import { prisma } from '../src/client.js'
import { Day, GlassSize, Limitations } from '../src/generated/prisma/client.js'

const REFERENCE_DATE = '2000-01-01'

function at(time: string) {
return `${REFERENCE_DATE}T${time}:00+01:00`
}

async function main() {
console.log('Seeding database...')

await prisma.todo.deleteMany()
await prisma.priceSighting.deleteMany()
await prisma.openingHours.deleteMany()
await prisma.venue.deleteMany()
await prisma.city.deleteMany()

const todos = await prisma.todo.createMany({
data: [
{ title: 'Buy groceries' },
{ title: 'Read a book' },
{ title: 'Workout' },
],
await prisma.city.create({
data: {
name: 'Trondheim',
centreLon: '10.3951',
centreLat: '63.4305',
venues: {
create: [
{
name: 'Den Gode Nabo',
address: 'Øvre Bakklandet 69',
openingHours: {
create: [
{
days: [Day.MON, Day.TUE, Day.WED, Day.THU, Day.FRI],
opening: at('15:00'),
closing: at('23:00'),
},
{
days: [Day.SAT, Day.SUN],
opening: at('12:00'),
closing: at('22:00'),
},
],
},
pricesSighted: {
create: [
{
price: 165,
size: GlassSize.PINT,
limitation: [],
},
{
price: 139,
size: GlassSize.PINT,
limitation: [Limitations.TIME],
timeStart: at('16:00'),
timeEnd: at('18:00'),
},
{
price: 149,
size: GlassSize.HALF_LITER,
limitation: [Limitations.MEMBERSHIP],
},
],
},
},
{
name: 'Skjenkestua',
address: 'Nedre Bakklandet 24',
openingHours: {
create: [
{
days: [Day.MON, Day.TUE, Day.WED, Day.THU],
opening: at('16:00'),
closing: at('23:30'),
},
{
days: [Day.FRI, Day.SAT],
opening: at('14:00'),
closing: at('23:30'),
},
],
},
pricesSighted: {
create: [
{
price: 149,
size: GlassSize.PINT,
limitation: [],
},
{
price: 89,
size: GlassSize.QUARTER_LITER,
limitation: [],
},
],
},
},
{
name: 'Baklandet Skydsstation',
address: 'Øvre Bakklandet 33',
openingHours: {
create: [
{
days: [Day.TUE, Day.WED, Day.THU, Day.FRI, Day.SAT, Day.SUN],
opening: at('17:00'),
closing: at('23:30'),
},
],
},
pricesSighted: {
create: [
{
price: 155,
size: GlassSize.PINT,
limitation: [],
},
{
price: 135,
size: GlassSize.HALF_LITER,
limitation: [],
},
],
},
},
{
name: 'Trondheim Torg Pub',
address: 'Olav Tryggvasons gate 6',
openingHours: {
create: [
{
days: [
Day.MON,
Day.TUE,
Day.WED,
Day.THU,
Day.FRI,
Day.SAT,
Day.SUN,
],
opening: at('10:00'),
closing: at('20:00'),
},
],
},
pricesSighted: {
create: [
{
price: 159,
size: GlassSize.PINT,
limitation: [],
},
{
price: 129,
size: GlassSize.HALF_LITER,
limitation: [Limitations.MEMBERSHIP],
},
],
},
},
],
},
},
})

console.log(`Created ${todos.count} todos`)
await prisma.city.create({
data: {
name: 'Oslo',
centreLon: '10.7522',
centreLat: '59.9139',
venues: {
create: [
{
name: 'The Dubliner Folk Pub',
address: 'Rådhusgata 13',
openingHours: {
create: [
{
days: [
Day.MON,
Day.TUE,
Day.WED,
Day.THU,
Day.FRI,
Day.SAT,
Day.SUN,
],
opening: at('14:00'),
closing: at('23:00'),
},
],
},
pricesSighted: {
create: [
{
price: 185,
size: GlassSize.PINT,
limitation: [],
},
],
},
},
{
name: 'Tilt',
address: 'Øvre Slottsgate 6',
openingHours: {
create: [
{
days: [
Day.MON,
Day.TUE,
Day.WED,
Day.THU,
Day.FRI,
Day.SAT,
Day.SUN,
],
opening: at('15:00'),
closing: at('23:00'),
},
],
},
pricesSighted: {
create: [
{
price: 175,
size: GlassSize.HALF_LITER,
limitation: [],
},
{
price: 60,
size: GlassSize.OTHER,
limitation: [],
sizeMl: 330,
},
],
},
},
],
},
},
})

const [cities, venues, openingHours, priceSightings] = await Promise.all([
prisma.city.count(),
prisma.venue.count(),
prisma.openingHours.count(),
prisma.priceSighting.count(),
])

console.log(
`Created ${cities} cities, ${venues} venues, ${openingHours} opening hours entries, and ${priceSightings} price sightings`,
)
}

main()
Expand Down