mirror of
https://github.com/michivonah/themepark-assistant.git
synced 2025-12-23 14:36:29 +01:00
setup drizzle for d1 & create db schema
This commit is contained in:
parent
3c197d8ebe
commit
fc3b1d1af5
8 changed files with 824 additions and 12 deletions
9
api/src/db/client.ts
Normal file
9
api/src/db/client.ts
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import { drizzle } from 'drizzle-orm/d1';
|
||||
import type { Context } from 'hono';
|
||||
|
||||
export function dbConnection(c: Context){
|
||||
return drizzle({
|
||||
connection: c.env.db,
|
||||
casing: 'snake_case'
|
||||
})
|
||||
}
|
||||
45
api/src/db/schema.ts
Normal file
45
api/src/db/schema.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { integer, text, sqliteTable } from "drizzle-orm/sqlite-core";
|
||||
|
||||
export const attraction = sqliteTable('attraction', {
|
||||
id: integer().primaryKey({ autoIncrement: true }),
|
||||
name: text().notNull(),
|
||||
apiCode: integer(),
|
||||
themeparkId: integer().notNull().references(() => themepark.id)
|
||||
})
|
||||
|
||||
export const attractionNotification = sqliteTable('attraction_notification', {
|
||||
id: integer().primaryKey({ autoIncrement: true}),
|
||||
userId: integer().notNull().references(() => user.id),
|
||||
attractionId: integer().notNull().references(() => attraction.id),
|
||||
notificationMethodId: integer().notNull().references(() => notificationMethod.id)
|
||||
})
|
||||
|
||||
export const logbook = sqliteTable('logbook', {
|
||||
id: integer().primaryKey({ autoIncrement: true }),
|
||||
userId: integer().notNull().references(() => user.id),
|
||||
attractionId: integer().notNull().references(() => attraction.id),
|
||||
timestamp: integer().notNull(), // unix timecode
|
||||
expectedWaittime: integer(),
|
||||
realWaittime: integer()
|
||||
})
|
||||
|
||||
export const notificationMethod = sqliteTable('notification', {
|
||||
id: integer().primaryKey({ autoIncrement: true }),
|
||||
webhookUrl: text().notNull(),
|
||||
shownName: text().notNull(),
|
||||
userId: integer().notNull().references(() => user.id)
|
||||
})
|
||||
|
||||
export const themepark = sqliteTable('themepark', {
|
||||
id: integer().primaryKey({ autoIncrement: true }),
|
||||
name: text().notNull(),
|
||||
countrycode: text().notNull(),
|
||||
website: text(),
|
||||
apiName: text()
|
||||
})
|
||||
|
||||
export const user = sqliteTable('user', {
|
||||
id: integer().primaryKey({ autoIncrement: true }),
|
||||
username: text().notNull(),
|
||||
isActive: integer({ mode: 'boolean' }).default(false)
|
||||
})
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
import { Hono } from 'hono'
|
||||
import { dbConnection } from './db/client'
|
||||
import { notificationMethod } from './db/schema'
|
||||
|
||||
const app = new Hono()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue