Skip to content

Commit 9d72ea1

Browse files
committed
chore!: update to boringnode/queue 0.4.0
1 parent 4572184 commit 9d72ea1

File tree

4 files changed

+26
-57
lines changed

4 files changed

+26
-57
lines changed

configure.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,12 @@ export async function configure(command: Configure) {
8383
* Create migration for database driver
8484
*/
8585
if (driver === 'database') {
86-
const shouldPublishMigration = await command.prompt.confirm(
87-
'Do you want to publish the migration for the queue tables?',
88-
{ hint: 'Tables are auto-created by default, but you can manage them manually' }
89-
)
90-
91-
if (shouldPublishMigration) {
92-
await codemods.makeUsingStub(stubsRoot, 'migration.stub', {
93-
entity: command.app.generators.createEntity('queue'),
94-
migration: {
95-
folder: 'database/migrations',
96-
fileName: `${new Date().getTime()}_create_queue_tables.ts`,
97-
},
98-
})
99-
}
86+
await codemods.makeUsingStub(stubsRoot, 'migration.stub', {
87+
entity: command.app.generators.createEntity('queue'),
88+
migration: {
89+
folder: 'database/migrations',
90+
fileName: `${new Date().getTime()}_create_queue_tables.ts`,
91+
},
92+
})
10093
}
10194
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"version": "npm run build"
3636
},
3737
"dependencies": {
38-
"@boringnode/queue": "^0.3.1",
38+
"@boringnode/queue": "^0.4.0",
3939
"@poppinss/utils": "^6.10.1"
4040
},
4141
"devDependencies": {

stubs/migration.stub

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,20 @@
44
})
55
}}}
66
import { BaseSchema } from '@adonisjs/lucid/schema'
7+
import { QueueSchemaService } from '@boringnode/queue'
78

89
export default class extends BaseSchema {
910
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())
2912

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()
5015
}
5116

5217
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()
5522
}
5623
}

tests/configure.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010
import { test } from '@japa/runner'
1111
import { fileURLToPath } from 'node:url'
12+
import { readdir } from 'node:fs/promises'
13+
import { join } from 'node:path'
1214
import { IgnitorFactory } from '@adonisjs/core/factories'
1315
import Configure from '@adonisjs/core/commands/configure'
1416

1517
const BASE_URL = new URL('./tmp/', import.meta.url)
18+
const BASE_PATH = fileURLToPath(BASE_URL)
1619

1720
test.group('Configure', (group) => {
1821
group.tap((t) => t.timeout(10_000))
@@ -25,6 +28,7 @@ test.group('Configure', (group) => {
2528
await context.fs.createJson('tsconfig.json', {})
2629
await context.fs.create('start/env.ts', `export default Env.create(new URL('./'), {})`)
2730
await context.fs.create('adonisrc.ts', `export default defineConfig({})`)
31+
await context.fs.create('database/migrations/.gitkeep', '')
2832
})
2933

3034
test('should register provider and command', async ({ assert }) => {
@@ -159,13 +163,18 @@ test.group('Configure', (group) => {
159163

160164
const ace = await app.container.make('ace')
161165
ace.prompt.trap('Select the queue driver you plan to use').chooseOption(1) // database
162-
ace.prompt.trap('Do you want to publish the migration for the queue tables?').reject()
163166
ace.ui.switchMode('raw')
164167

165168
const command = await ace.create(Configure, ['../../index.js'])
166169
await command.exec()
167170

168171
await assert.fileContains('config/queue.ts', 'drivers.database')
169172
await assert.fileContains('.env', 'QUEUE_DRIVER=database')
173+
174+
const migrationDir = join(BASE_PATH, 'database/migrations')
175+
const migrationFiles = await readdir(migrationDir)
176+
const hasQueueMigration = migrationFiles.some((file) => file.endsWith('_create_queue_tables.ts'))
177+
178+
assert.isTrue(hasQueueMigration)
170179
})
171180
})

0 commit comments

Comments
 (0)