Files
Autonomous-Bug-Explorer/dist/db/migrations/003_jobs_table.js
2026-03-05 09:44:06 -05:00

37 lines
1.5 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.up = up;
exports.down = down;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function up(db) {
await db.schema.createTable('jobs')
.ifNotExists()
.addColumn('id', 'text', col => col.primaryKey())
.addColumn('type', 'text', col => col.notNull())
.addColumn('status', 'text', col => col.notNull().defaultTo('pending'))
.addColumn('payload', 'text', col => col.notNull())
.addColumn('result', 'text')
.addColumn('error', 'text')
.addColumn('attempts', 'integer', col => col.notNull().defaultTo(0))
.addColumn('max_attempts', 'integer', col => col.notNull().defaultTo(3))
.addColumn('priority', 'integer', col => col.notNull().defaultTo(0))
.addColumn('run_at', 'text', col => col.notNull())
.addColumn('started_at', 'text')
.addColumn('completed_at', 'text')
.addColumn('created_at', 'text', col => col.notNull())
.addColumn('updated_at', 'text', col => col.notNull())
.execute();
// Index for efficient polling
await db.schema
.createIndex('idx_jobs_poll')
.ifNotExists()
.on('jobs')
.columns(['status', 'run_at', 'priority'])
.execute();
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function down(db) {
await db.schema.dropIndex('idx_jobs_poll').ifExists().execute();
await db.schema.dropTable('jobs').ifExists().execute();
}