mirror of
https://github.com/whekin/household-bot.git
synced 2026-03-31 18:54:03 +00:00
feat(WHE-27): add drizzle db package and typed env config
This commit is contained in:
28
packages/db/src/schema.ts
Normal file
28
packages/db/src/schema.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { index, integer, pgTable, text, timestamp, uniqueIndex, uuid } from 'drizzle-orm/pg-core'
|
||||
|
||||
export const households = pgTable('households', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
name: text('name').notNull(),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull()
|
||||
})
|
||||
|
||||
export const members = pgTable(
|
||||
'members',
|
||||
{
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
householdId: uuid('household_id')
|
||||
.notNull()
|
||||
.references(() => households.id, { onDelete: 'cascade' }),
|
||||
telegramUserId: text('telegram_user_id').notNull(),
|
||||
displayName: text('display_name').notNull(),
|
||||
isAdmin: integer('is_admin').default(0).notNull(),
|
||||
joinedAt: timestamp('joined_at', { withTimezone: true }).defaultNow().notNull()
|
||||
},
|
||||
(table) => ({
|
||||
householdIdx: index('members_household_idx').on(table.householdId),
|
||||
householdTgUserUnique: uniqueIndex('members_household_tg_user_unique').on(
|
||||
table.householdId,
|
||||
table.telegramUserId
|
||||
)
|
||||
})
|
||||
)
|
||||
Reference in New Issue
Block a user