const tableName = 'vk_webhook_deliveries' function buildTable(t) { t.string('id', 64).primary() t.bigInteger('event_id').unsigned().notNullable() t.string('agent_id', 64).notNullable() t.string('status', 16).notNullable() t.tinyint('attempts').unsigned().notNullable() t.datetime('next_attempt_at', { precision: 3 }).nullable() t.datetime('created_at', { precision: 3 }).notNullable() t.datetime('delivered_at', { precision: 3 }).nullable() t.unique(['event_id', 'agent_id'], { indexName: 'uq_vk_webhook_deliveries_event_agent' }) t.index(['status', 'next_attempt_at'], 'idx_vk_webhook_deliveries_due') t.check("status in ('pending','delivered','failed')", [], 'ck_vk_webhook_deliveries_status') t.check("(status = 'pending') = (next_attempt_at is not null)", [], 'ck_vk_webhook_deliveries_next_attempt') t.check("(status = 'delivered') = (delivered_at is not null)", [], 'ck_vk_webhook_deliveries_delivered') } module.exports = { tableName, buildTable }