mirror of
https://github.com/michivonah/themepark-assistant.git
synced 2025-12-22 22:16:29 +01:00
add db constraints for better data validation & preventing redundant data
This commit is contained in:
parent
3574559ead
commit
a185b29875
1 changed files with 23 additions and 15 deletions
|
|
@ -1,37 +1,45 @@
|
||||||
import { check, integer, text, sqliteTable, sqliteView } from "drizzle-orm/sqlite-core";
|
import { check, integer, text, sqliteTable, sqliteView, unique } from "drizzle-orm/sqlite-core";
|
||||||
import { eq, sql } from "drizzle-orm";
|
import { eq, sql } from "drizzle-orm";
|
||||||
|
|
||||||
// Tables
|
// Tables
|
||||||
export const attraction = sqliteTable('attraction', {
|
export const attraction = sqliteTable('attraction', {
|
||||||
id: integer().primaryKey({ autoIncrement: true }),
|
id: integer().primaryKey({ autoIncrement: true }),
|
||||||
name: text().notNull(),
|
name: text().notNull(),
|
||||||
apiCode: text().notNull().unique(),
|
apiCode: text('api_code').notNull().unique(),
|
||||||
themeparkId: integer().notNull().references(() => themepark.id)
|
themeparkId: integer('themepark_id').notNull().references(() => themepark.id)
|
||||||
})
|
}, (t) => [
|
||||||
|
unique().on(t.apiCode, t.themeparkId)
|
||||||
|
])
|
||||||
|
|
||||||
export const attractionNotification = sqliteTable('attraction_notification', {
|
export const attractionNotification = sqliteTable('attraction_notification', {
|
||||||
id: integer().primaryKey({ autoIncrement: true}),
|
id: integer().primaryKey({ autoIncrement: true}),
|
||||||
userId: integer().notNull().references(() => user.id),
|
userId: integer('user_id').notNull().references(() => user.id),
|
||||||
attractionId: integer().notNull().references(() => attraction.id),
|
attractionId: integer('attraction_id').notNull().references(() => attraction.id),
|
||||||
notificationMethodId: integer().notNull().references(() => notificationMethod.id)
|
notificationMethodId: integer('notification_method_id').notNull().references(() => notificationMethod.id)
|
||||||
})
|
}, (t) => [
|
||||||
|
unique().on(t.userId, t.attractionId, t.notificationMethodId)
|
||||||
|
])
|
||||||
|
|
||||||
export const logbook = sqliteTable('logbook', {
|
export const logbook = sqliteTable('logbook', {
|
||||||
id: integer().primaryKey({ autoIncrement: true }),
|
id: integer().primaryKey({ autoIncrement: true }),
|
||||||
userId: integer().notNull().references(() => user.id),
|
userId: integer('user_id').notNull().references(() => user.id),
|
||||||
attractionId: integer().notNull().references(() => attraction.id),
|
attractionId: integer('attraction_id').notNull().references(() => attraction.id),
|
||||||
timestamp: integer().notNull(), // unix timecode
|
timestamp: integer().notNull(), // unix timecode
|
||||||
expectedWaittime: integer(),
|
expectedWaittime: integer(),
|
||||||
realWaittime: integer()
|
realWaittime: integer()
|
||||||
})
|
}, (t) => [
|
||||||
|
unique().on(t.userId, t.attractionId, t.timestamp)
|
||||||
|
])
|
||||||
|
|
||||||
export const notificationMethod = sqliteTable('notification_method', {
|
export const notificationMethod = sqliteTable('notification_method', {
|
||||||
id: integer().primaryKey({ autoIncrement: true }),
|
id: integer().primaryKey({ autoIncrement: true }),
|
||||||
webhookUrl: text().notNull(),
|
webhookUrl: text('webhook_url').notNull(),
|
||||||
shownName: text().notNull(),
|
shownName: text().notNull(),
|
||||||
userId: integer().notNull().references(() => user.id),
|
userId: integer('user_id').notNull().references(() => user.id),
|
||||||
notificationProviderId: integer().notNull().references(() => notificationProvider.id),
|
notificationProviderId: integer('notification_provider_id').notNull().references(() => notificationProvider.id),
|
||||||
})
|
}, (t) => [
|
||||||
|
unique().on(t.webhookUrl, t.userId, t.notificationProviderId)
|
||||||
|
])
|
||||||
|
|
||||||
export const notificationProvider = sqliteTable('notification_provider', {
|
export const notificationProvider = sqliteTable('notification_provider', {
|
||||||
id: integer().primaryKey({ autoIncrement: true }),
|
id: integer().primaryKey({ autoIncrement: true }),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue