2024-10-19 10:00:35 +00:00
|
|
|
import { Kysely, sql } from 'npm:kysely'
|
|
|
|
|
|
|
|
// Just a shortcut cuz my monitor is small
|
|
|
|
const tg_id = 'users.tg_id'
|
|
|
|
|
|
|
|
export async function up(db: Kysely<any>): Promise<void> {
|
2024-10-23 16:09:10 +00:00
|
|
|
await db.schema.createTable('users')
|
|
|
|
.addColumn('id', 'uuid',
|
|
|
|
col => col.defaultTo(sql`gen_random_uuid()`).primaryKey())
|
|
|
|
.addColumn('joined_by_referal_from_user_id', 'uuid',
|
|
|
|
col => col.references('users.id').onDelete('no action'))
|
|
|
|
.addColumn('tg_id', 'bigint',
|
|
|
|
col => col.defaultTo(sql`null`).unique())
|
|
|
|
.addColumn('is_chat_participant', 'boolean',
|
|
|
|
col => col.defaultTo(sql`false`).notNull())
|
|
|
|
.addColumn('is_captcha_passed', 'boolean',
|
|
|
|
col => col.defaultTo(sql`false`).notNull())
|
|
|
|
.addColumn('is_timeout', 'boolean',
|
|
|
|
col => col.defaultTo(sql`false`).notNull())
|
|
|
|
.addColumn('is_banned', 'boolean',
|
|
|
|
col => col.defaultTo(sql`false`).notNull())
|
|
|
|
.addColumn('created_at', 'timestamp',
|
|
|
|
col => col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull())
|
|
|
|
.addColumn('joined_chat_at', 'timestamp',
|
|
|
|
col => col.defaultTo(sql`null`))
|
|
|
|
.addColumn('timeout_until', 'timestamp',
|
|
|
|
col => col.defaultTo(sql`null`))
|
|
|
|
.execute()
|
2024-10-19 10:00:35 +00:00
|
|
|
|
2024-10-23 16:09:10 +00:00
|
|
|
await db.schema.createTable('invite_links')
|
|
|
|
.addColumn('link', 'text', col => col.primaryKey())
|
|
|
|
.addColumn('expect_user_tg_id', 'bigint', col => col.references(tg_id).onDelete('cascade').notNull())
|
|
|
|
.addColumn('valid_until', 'timestamp', col => col)
|
|
|
|
.execute()
|
2024-10-19 10:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function down(db: Kysely<any>): Promise<void> {
|
|
|
|
await db.schema.dropTable("users").execute()
|
|
|
|
await db.schema.dropTable("invite_link").execute()
|
|
|
|
}
|