Skip to content

Commit 25f9c69

Browse files
committed
Merge branch 'master' of github.com:timgit/pg-boss
2 parents 4de92c6 + 877387e commit 25f9c69

8 files changed

+59
-33
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pg-boss",
3-
"version": "10.0.5",
3+
"version": "10.0.6",
44
"description": "Queueing jobs in Postgres from Node.js like a boss",
55
"main": "./src/index.js",
66
"engines": {

src/contractor.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ class Contractor {
4646
const version = await this.schemaVersion()
4747

4848
if (schemaVersion > version) {
49-
throw new Error('Migrations are not supported to v10')
50-
// await this.migrate(version)
49+
await this.migrate(version)
5150
}
5251
} else {
5352
await this.create()
@@ -86,15 +85,15 @@ class Contractor {
8685
}
8786
}
8887

89-
// async next (version) {
90-
// const commands = migrationStore.next(this.config.schema, version, this.migrations)
91-
// await this.db.executeSql(commands)
92-
// }
88+
async next (version) {
89+
const commands = migrationStore.next(this.config.schema, version, this.migrations)
90+
await this.db.executeSql(commands)
91+
}
9392

94-
// async rollback (version) {
95-
// const commands = migrationStore.rollback(this.config.schema, version, this.migrations)
96-
// await this.db.executeSql(commands)
97-
// }
93+
async rollback (version) {
94+
const commands = migrationStore.rollback(this.config.schema, version, this.migrations)
95+
await this.db.executeSql(commands)
96+
}
9897
}
9998

10099
module.exports = Contractor

src/migrationStore.js

+11
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,16 @@ function migrate (value, version, migrations) {
6464

6565
function getAll (schema) {
6666
return [
67+
{
68+
release: '10.0.6',
69+
version: 22,
70+
previous: 21,
71+
install: [
72+
`ALTER TABLE ${schema}.job ALTER COLUMN retry_limit SET DEFAULT 2`
73+
],
74+
uninstall: [
75+
`ALTER TABLE ${schema}.job ALTER COLUMN retry_limit SET DEFAULT 0`
76+
]
77+
}
6778
]
6879
}

src/plans.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ function createTableJob (schema) {
179179
priority integer not null default(0),
180180
data jsonb,
181181
state ${schema}.job_state not null default('${JOB_STATES.created}'),
182-
retry_limit integer not null default(0),
182+
retry_limit integer not null default(2),
183183
retry_count integer not null default(0),
184184
retry_delay integer not null default(0),
185185
retry_backoff boolean not null default false,

test/migrationTest.js

+33-17
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,39 @@ describe('migration', function () {
3232
}
3333
})
3434

35-
it.skip('should migrate to previous version and back again', async function () {
35+
it('should migrate to previous version and back again', async function () {
3636
const { contractor } = this.test
3737

3838
await contractor.create()
3939

4040
await contractor.rollback(currentSchemaVersion)
41-
const oldVersion = await contractor.version()
41+
const oldVersion = await contractor.schemaVersion()
4242

4343
assert.notStrictEqual(oldVersion, currentSchemaVersion)
4444

4545
await contractor.migrate(oldVersion)
46-
const newVersion = await contractor.version()
46+
const newVersion = await contractor.schemaVersion()
4747

4848
assert.strictEqual(newVersion, currentSchemaVersion)
4949
})
5050

51-
it.skip('should migrate to latest during start if on previous schema version', async function () {
51+
it('should install next version via contractor', async function () {
52+
const { contractor } = this.test
53+
54+
await contractor.create()
55+
56+
await contractor.rollback(currentSchemaVersion)
57+
58+
const oneVersionAgo = await contractor.schemaVersion()
59+
60+
await contractor.next(oneVersionAgo)
61+
62+
const version = await contractor.schemaVersion()
63+
64+
assert.strictEqual(version, currentSchemaVersion)
65+
})
66+
67+
it('should migrate to latest during start if on previous schema version', async function () {
5268
const { contractor } = this.test
5369

5470
await contractor.create()
@@ -61,7 +77,7 @@ describe('migration', function () {
6177

6278
await boss.start()
6379

64-
const version = await contractor.version()
80+
const version = await contractor.schemaVersion()
6581

6682
assert.strictEqual(version, currentSchemaVersion)
6783
})
@@ -88,22 +104,22 @@ describe('migration', function () {
88104
await boss.send(queue)
89105

90106
await contractor.rollback(currentSchemaVersion)
91-
const oneVersionAgo = await contractor.version()
107+
const oneVersionAgo = await contractor.schemaVersion()
92108

93109
assert.notStrictEqual(oneVersionAgo, currentSchemaVersion)
94110

95111
await contractor.rollback(oneVersionAgo)
96-
const twoVersionsAgo = await contractor.version()
112+
const twoVersionsAgo = await contractor.schemaVersion()
97113

98114
assert.notStrictEqual(twoVersionsAgo, oneVersionAgo)
99115

100116
await contractor.next(twoVersionsAgo)
101-
const oneVersionAgoPart2 = await contractor.version()
117+
const oneVersionAgoPart2 = await contractor.schemaVersion()
102118

103119
assert.strictEqual(oneVersionAgo, oneVersionAgoPart2)
104120

105121
await contractor.next(oneVersionAgo)
106-
const version = await contractor.version()
122+
const version = await contractor.schemaVersion()
107123

108124
assert.strictEqual(version, currentSchemaVersion)
109125

@@ -118,18 +134,18 @@ describe('migration', function () {
118134
await contractor.create()
119135

120136
await contractor.rollback(currentSchemaVersion)
121-
const oneVersionAgo = await contractor.version()
137+
const oneVersionAgo = await contractor.schemaVersion()
122138
assert.strictEqual(oneVersionAgo, currentSchemaVersion - 1)
123139

124140
await contractor.rollback(oneVersionAgo)
125-
const twoVersionsAgo = await contractor.version()
141+
const twoVersionsAgo = await contractor.schemaVersion()
126142
assert.strictEqual(twoVersionsAgo, currentSchemaVersion - 2)
127143

128144
const config = { ...this.test.bossConfig }
129145
const boss = this.test.boss = new PgBoss(config)
130146
await boss.start()
131147

132-
const version = await contractor.version()
148+
const version = await contractor.schemaVersion()
133149

134150
assert.strictEqual(version, currentSchemaVersion)
135151
})
@@ -146,7 +162,7 @@ describe('migration', function () {
146162
}
147163
})
148164

149-
it.skip('should roll back an error during a migration', async function () {
165+
it('should roll back an error during a migration', async function () {
150166
const { contractor } = this.test
151167

152168
const config = { ...this.test.bossConfig }
@@ -158,7 +174,7 @@ describe('migration', function () {
158174

159175
await contractor.create()
160176
await contractor.rollback(currentSchemaVersion)
161-
const oneVersionAgo = await contractor.version()
177+
const oneVersionAgo = await contractor.schemaVersion()
162178

163179
const boss1 = new PgBoss(config)
164180

@@ -170,7 +186,7 @@ describe('migration', function () {
170186
await boss1.stop({ graceful: false, wait: false })
171187
}
172188

173-
const version1 = await contractor.version()
189+
const version1 = await contractor.schemaVersion()
174190

175191
assert.strictEqual(version1, oneVersionAgo)
176192

@@ -181,7 +197,7 @@ describe('migration', function () {
181197

182198
await boss2.start()
183199

184-
const version2 = await contractor.version()
200+
const version2 = await contractor.schemaVersion()
185201

186202
assert.strictEqual(version2, currentSchemaVersion)
187203

@@ -199,7 +215,7 @@ describe('migration', function () {
199215
}
200216
})
201217

202-
it.skip('should not migrate if migrate option is false', async function () {
218+
it('should not migrate if migrate option is false', async function () {
203219
const { contractor } = this.test
204220

205221
await contractor.create()

test/multiMasterTest.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('multi-master', function () {
3939

4040
await contractor.rollback(currentSchemaVersion)
4141

42-
const oldVersion = await contractor.version()
42+
const oldVersion = await contractor.schemaVersion()
4343

4444
assert.notStrictEqual(oldVersion, currentSchemaVersion)
4545

version.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"schema": 21
2+
"schema": 22
33
}

0 commit comments

Comments
 (0)