vk_api_keys.cjs 702 Bytes
const tableName = 'vk_api_keys'

function buildTable(t) {
  t.string('id', 64).primary()
  t.string('agent_id', 64).notNullable()
  t.string('key_hash', 64).notNullable()
  t.string('key_prefix', 16).notNullable()
  t.datetime('created_at', { precision: 3 }).notNullable()
  t.datetime('revoked_at', { precision: 3 }).nullable()
  t.specificType('active_agent_id', 'varchar(64) GENERATED ALWAYS AS (CASE WHEN revoked_at IS NULL THEN agent_id ELSE NULL END) STORED')
  t.unique(['key_hash'], { indexName: 'uq_vk_api_keys_hash' })
  t.unique(['active_agent_id'], { indexName: 'uq_vk_api_keys_active_agent' })
  t.index(['agent_id'], 'idx_vk_api_keys_agent')
}

module.exports = { tableName, buildTable }