vk_agents.cjs
1.75 KB
const tableName = 'vk_agents'
function buildTable(t) {
t.string('id', 64).primary()
t.string('wallet_user_id', 64).notNullable()
t.string('owner_user_id', 64).nullable()
t.string('guild_id', 64).nullable()
t.string('role', 16).notNullable()
t.string('status', 16).notNullable()
t.string('name', 120).notNullable()
t.string('description', 1000).nullable()
t.json('skills').notNullable()
t.string('owner_email', 320).nullable()
t.integer('level').unsigned().notNullable()
t.bigInteger('xp').unsigned().notNullable()
t.string('webhook_url', 2048).nullable()
t.text('webhook_secret_enc').nullable()
t.bigInteger('daily_spend_limit').nullable()
t.bigInteger('events_cursor').unsigned().notNullable()
t.datetime('claimed_at', { precision: 3 }).nullable()
t.datetime('created_at', { precision: 3 }).notNullable()
t.datetime('updated_at', { precision: 3 }).nullable()
t.unique(['wallet_user_id'], { indexName: 'uq_vk_agents_wallet' })
t.index(['owner_user_id'], 'idx_vk_agents_owner')
t.index(['guild_id', 'status'], 'idx_vk_agents_guild_status')
t.check("role in ('company','member')", [], 'ck_vk_agents_role')
t.check("status in ('pending_claim','active','suspended')", [], 'ck_vk_agents_status')
t.check("(status = 'pending_claim' and owner_user_id is null and claimed_at is null and guild_id is null) or (status <> 'pending_claim' and owner_user_id is not null and claimed_at is not null and guild_id is not null)", [], 'ck_vk_agents_claim')
t.check('(webhook_url is null) = (webhook_secret_enc is null)', [], 'ck_vk_agents_webhook_pair')
t.check('level >= 1', [], 'ck_vk_agents_level')
t.check('daily_spend_limit is null or daily_spend_limit >= 0', [], 'ck_vk_agents_daily_spend_limit')
}
module.exports = { tableName, buildTable }