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): Promise { await db.schema.createTable('users') .addColumn('id', 'uuid', col => col.defaultTo(sql`gen_random_uuid()`).primaryKey().onDelete('cascade')) .addColumn('joined_byreferal_from_user_id', 'uuid', col => col.defaultTo(sql`gen_random_uuid()`).primaryKey().onDelete('cascade')) .addColumn('tg_id', 'bigint', col => col) .addColumn('is_chat_participant', 'boolean', col => col.defaultTo(false).notNull()) .addColumn('is_captcha_passed', 'boolean', col => col.defaultTo(false).notNull()) .addColumn('is_timeout', 'boolean', col => col.defaultTo(false).notNull()) .addColumn('is_banned', 'boolean', col => col.defaultTo(false).notNull()) .addColumn('created_at', 'timestamp', col => col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()) .addColumn('joined_chat_at', 'timestamp', col => col) .addColumn('timeout_until', 'timestamp', col => col) .execute() await db.schema.createTable('invite_links') .addColumn('link', 'text', col => col.primaryKey()) .addColumn('expect_user_tg_id', 'bigint', col => col.references(tg_id).notNull()) .execute() } export async function down(db: Kysely): Promise { await db.schema.dropTable("users").execute() await db.schema.dropTable("joined_by_referal").execute() await db.schema.dropTable("invite_link").execute() }