|
| 1 | +/** |
| 2 | + * @param { import("knex").Knex } knex |
| 3 | + * @returns { Promise<void> } |
| 4 | + */ |
| 5 | +export async function up(knex) { |
| 6 | + await knex.schema.createTable('form_jobs', table => { |
| 7 | + table.uuid('id').primary(); |
| 8 | + |
| 9 | + // Foreign key to forms (CASCADE delete: jobs belong to forms) |
| 10 | + table |
| 11 | + .uuid('form_id') |
| 12 | + .notNullable() |
| 13 | + .references('id') |
| 14 | + .inTable('forms') |
| 15 | + .onDelete('CASCADE'); |
| 16 | + |
| 17 | + // Job type - extensible for future operations |
| 18 | + table.text('job_type').notNullable(); |
| 19 | + // Values: 'import-pdf', 'validate-schema', 'publish', 'export', etc. |
| 20 | + |
| 21 | + // Job status - represents operation state |
| 22 | + table.text('status').notNullable(); |
| 23 | + // Values: 'pending', 'processing', 'completed', 'failed' |
| 24 | + |
| 25 | + // Timing information |
| 26 | + table.timestamp('created_at').notNullable().defaultTo(knex.fn.now()); |
| 27 | + table.timestamp('started_at').nullable(); |
| 28 | + table.timestamp('completed_at').nullable(); |
| 29 | + |
| 30 | + // Error tracking |
| 31 | + table.text('error_message').nullable(); |
| 32 | + table.text('error_stack').nullable(); |
| 33 | + |
| 34 | + // Job metadata (input parameters, varies by job_type) |
| 35 | + // For 'import-pdf': { documentId, fileName, userId } |
| 36 | + // For 'publish': { targetEnvironment, publisherId } |
| 37 | + table.text('metadata').nullable(); |
| 38 | + |
| 39 | + // Job result (output data, varies by job_type) |
| 40 | + // For 'import-pdf': { patternsAdded: 5, fieldsExtracted: 12 } |
| 41 | + // For 'validate': { errorsFound: 2, warningsFound: 5 } |
| 42 | + table.text('result').nullable(); |
| 43 | + |
| 44 | + // Indexes for common queries |
| 45 | + table.index('form_id', 'idx_form_jobs_form_id'); |
| 46 | + table.index('status', 'idx_form_jobs_status'); |
| 47 | + table.index(['form_id', 'job_type'], 'idx_form_jobs_form_type'); |
| 48 | + table.index('created_at', 'idx_form_jobs_created'); |
| 49 | + }); |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * @param { import("knex").Knex } knex |
| 54 | + * @returns { Promise<void> } |
| 55 | + */ |
| 56 | +export async function down(knex) { |
| 57 | + await knex.schema.dropTableIfExists('form_jobs'); |
| 58 | +} |
0 commit comments