|
4 | 4 | }) |
5 | 5 | }}} |
6 | 6 | import { BaseSchema } from '@adonisjs/lucid/schema' |
| 7 | +import { QueueSchemaService } from '@boringnode/queue' |
7 | 8 |
|
8 | 9 | export default class extends BaseSchema { |
9 | 10 | async up() { |
10 | | - /** |
11 | | - * Jobs table - stores pending, active, and delayed jobs |
12 | | - */ |
13 | | - this.schema.createTable('queue_jobs', (table) => { |
14 | | - table.string('id', 255).notNullable() |
15 | | - table.string('queue', 255).notNullable() |
16 | | - table.enu('status', ['pending', 'active', 'delayed', 'completed', 'failed']).notNullable() |
17 | | - table.text('data').notNullable() |
18 | | - table.bigint('score').unsigned().nullable() |
19 | | - table.string('worker_id', 255).nullable() |
20 | | - table.bigint('acquired_at').unsigned().nullable() |
21 | | - table.bigint('execute_at').unsigned().nullable() |
22 | | - table.bigint('finished_at').unsigned().nullable() |
23 | | - table.text('error').nullable() |
24 | | - table.primary(['id', 'queue']) |
25 | | - table.index(['queue', 'status', 'score']) |
26 | | - table.index(['queue', 'status', 'execute_at']) |
27 | | - table.index(['queue', 'status', 'finished_at']) |
28 | | - }) |
| 11 | + const schemaService = new QueueSchemaService(this.db.connection().getWriteClient()) |
29 | 12 |
|
30 | | - /** |
31 | | - * Schedules table - stores recurring job schedules |
32 | | - */ |
33 | | - this.schema.createTable('queue_schedules', (table) => { |
34 | | - table.string('id', 255).primary() |
35 | | - table.string('status', 50).notNullable().defaultTo('active') |
36 | | - table.string('name', 255).notNullable() |
37 | | - table.text('payload').notNullable() |
38 | | - table.string('cron_expression', 255).nullable() |
39 | | - table.bigint('every_ms').unsigned().nullable() |
40 | | - table.string('timezone', 100).notNullable().defaultTo('UTC') |
41 | | - table.timestamp('from_date').nullable() |
42 | | - table.timestamp('to_date').nullable() |
43 | | - table.integer('run_limit').unsigned().nullable() |
44 | | - table.integer('run_count').unsigned().notNullable().defaultTo(0) |
45 | | - table.timestamp('next_run_at').nullable() |
46 | | - table.timestamp('last_run_at').nullable() |
47 | | - table.timestamp('created_at').notNullable().defaultTo(this.now()) |
48 | | - table.index(['status', 'next_run_at']) |
49 | | - }) |
| 13 | + await schemaService.createJobsTable() |
| 14 | + await schemaService.createSchedulesTable() |
50 | 15 | } |
51 | 16 |
|
52 | 17 | async down() { |
53 | | - this.schema.dropTable('queue_jobs') |
54 | | - this.schema.dropTable('queue_schedules') |
| 18 | + const schemaService = new QueueSchemaService(this.db.connection().getWriteClient()) |
| 19 | + |
| 20 | + await schemaService.dropSchedulesTable() |
| 21 | + await schemaService.dropJobsTable() |
55 | 22 | } |
56 | 23 | } |
0 commit comments