You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
website/src/db/schema.ts

44 lines
1.5 KiB
TypeScript

import { sql } from 'drizzle-orm'
import { text, sqliteTable } from 'drizzle-orm/sqlite-core'
export const users = sqliteTable('users', {
// id è l'id unico di questo utente, non è modificabile una volta creato l'utente.
id: text('id')
.primaryKey()
.default(sql`(lower(hex(randomblob(16))))`),
// Username è il nome leggibile di questo utente utilizzato anche per le
// route per singolo utente, deve essere unico nel sito.
//
// NOTE: Quando un utente accede per la prima volta di default gli viene
// chiesto se usare quello dell'account che sta usando o se cambiarlo
// (in teoria non dovrebbe essere un problema poterlo modificare
// successivamente).
username: text('username').unique().notNull(),
// FullName da mostrare in giro per il sito
fullName: text('fullname'),
// Email per eventuale contatto
email: text('email'),
})
export type User = typeof users.$inferSelect // return type when queried
export type InsertUser = typeof users.$inferInsert // insert type
export const accounts = sqliteTable('accounts', {
// id è l'id unico di questo account, non è modificabile una volta creato l'account.
id: text('id').primaryKey(),
userId: text('userId')
.notNull()
.references(() => users.id),
provider: text('provider').$type<'poisson' | 'ateneo'>().notNull(),
token: text('token').notNull(),
})
export type Account = typeof accounts.$inferSelect // return type when queried
export type InsertAccount = typeof accounts.$inferInsert // insert type