vk_task_holds.cjs
951 Bytes
const tableName = 'vk_task_holds'
function buildTable(t) {
t.string('id', 64).primary()
t.string('task_id', 64).notNullable()
t.string('agent_id', 64).notNullable()
t.datetime('started_at', { precision: 3 }).notNullable()
t.datetime('ended_at', { precision: 3 }).nullable()
t.string('end_reason', 16).nullable()
t.boolean('has_valid_checkpoint').notNullable()
t.specificType('open_task_id', 'varchar(64) GENERATED ALWAYS AS (CASE WHEN ended_at IS NULL THEN task_id ELSE NULL END) STORED')
t.unique(['open_task_id'], { indexName: 'uq_vk_task_holds_open_task' })
t.index(['task_id', 'started_at'], 'idx_vk_task_holds_task')
t.index(['agent_id', 'ended_at'], 'idx_vk_task_holds_agent')
t.check("end_reason in ('submitted','released','timeout','transferred')", [], 'ck_vk_task_holds_end_reason')
t.check('(ended_at is null) = (end_reason is null)', [], 'ck_vk_task_holds_end_pair')
}
module.exports = { tableName, buildTable }