Skip to content

Commit 9bf8f24

Browse files
authoredMay 22, 2023
feat: add disable-locks flag (#932)
1 parent 8955b12 commit 9bf8f24

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
lines changed
 

‎adonis-typings/migrator.ts

+3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ declare module '@ioc:Adonis/Lucid/Migrator' {
2020
direction: 'up'
2121
connectionName?: string
2222
dryRun?: boolean
23+
disableLocks?: boolean
2324
}
2425
| {
2526
direction: 'down'
2627
batch?: number
2728
connectionName?: string
2829
dryRun?: boolean
30+
disableLocks?: boolean
2931
}
3032

3133
/**
@@ -53,6 +55,7 @@ declare module '@ioc:Adonis/Lucid/Migrator' {
5355
*/
5456
export interface MigratorContract extends EventEmitter {
5557
dryRun: boolean
58+
disableLocks: boolean
5659
version: number
5760
direction: 'up' | 'down'
5861
status: 'completed' | 'skipped' | 'pending' | 'error'

‎commands/Migration/Refresh.ts

+10
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export default class Refresh extends BaseCommand {
4444
@flags.boolean({ description: 'Run seeders' })
4545
public seed: boolean
4646

47+
/**
48+
* Disable advisory locks
49+
*/
50+
@flags.boolean({ description: 'Disable advisory locks' })
51+
public disableLocks: boolean
52+
4753
/**
4854
* Converting command properties to arguments
4955
*/
@@ -61,6 +67,10 @@ export default class Refresh extends BaseCommand {
6167
args.push('--dry-run')
6268
}
6369

70+
if (this.disableLocks) {
71+
args.push('--disable-locks')
72+
}
73+
6474
return args
6575
}
6676

‎commands/Migration/Reset.ts

+10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ export default class Reset extends BaseCommand {
3838
@flags.boolean({ description: 'Do not run actual queries. Instead view the SQL output' })
3939
public dryRun: boolean
4040

41+
/**
42+
* Disable advisory locks
43+
*/
44+
@flags.boolean({ description: 'Disable advisory locks' })
45+
public disableLocks: boolean
46+
4147
/**
4248
* Converting command properties to arguments
4349
*/
@@ -55,6 +61,10 @@ export default class Reset extends BaseCommand {
5561
args.push('--dry-run')
5662
}
5763

64+
if (this.disableLocks) {
65+
args.push('--disable-locks')
66+
}
67+
5868
return args
5969
}
6070

‎commands/Migration/Rollback.ts

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ export default class Migrate extends MigrationsBase {
5757
@flags.boolean({ description: 'A compact single-line output' })
5858
public compactOutput: boolean = false
5959

60+
/**
61+
* Disable advisory locks
62+
*/
63+
@flags.boolean({ description: 'Disable advisory locks' })
64+
public disableLocks: boolean
65+
6066
/**
6167
* Instantiating the migrator instance
6268
*/
@@ -69,6 +75,7 @@ export default class Migrate extends MigrationsBase {
6975
connectionName: this.connection,
7076
batch: this.batch,
7177
dryRun: this.dryRun,
78+
disableLocks: this.disableLocks
7279
})
7380
}
7481

‎commands/Migration/Run.ts

+7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ export default class Migrate extends MigrationsBase {
4848
@flags.boolean({ description: 'A compact single-line output' })
4949
public compactOutput: boolean = false
5050

51+
/**
52+
* Disable advisory locks
53+
*/
54+
@flags.boolean({ description: 'Disable advisory locks' })
55+
public disableLocks: boolean
56+
5157
/**
5258
* Instantiating the migrator instance
5359
*/
@@ -59,6 +65,7 @@ export default class Migrate extends MigrationsBase {
5965
direction: 'up',
6066
connectionName: this.connection,
6167
dryRun: this.dryRun,
68+
disableLocks: this.disableLocks,
6269
})
6370
}
6471

‎src/Migrator/index.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ export class Migrator extends EventEmitter implements MigratorContract {
8080
*/
8181
public dryRun: boolean = !!this.options.dryRun
8282

83+
/**
84+
* Disable advisory locks
85+
*/
86+
public disableLocks: boolean = !!this.options.disableLocks
87+
8388
/**
8489
* An array of files we have successfully migrated. The files are
8590
* collected regardless of `up` or `down` methods
@@ -252,7 +257,7 @@ export class Migrator extends EventEmitter implements MigratorContract {
252257
* to the real execution cycle
253258
*/
254259
private async acquireLock() {
255-
if (!this.client.dialect.supportsAdvisoryLocks) {
260+
if (!this.client.dialect.supportsAdvisoryLocks || this.disableLocks) {
256261
return
257262
}
258263

@@ -268,7 +273,7 @@ export class Migrator extends EventEmitter implements MigratorContract {
268273
* `Mysql`, `PostgreSQL` and `MariaDb` for now.
269274
*/
270275
private async releaseLock() {
271-
if (!this.client.dialect.supportsAdvisoryLocks) {
276+
if (!this.client.dialect.supportsAdvisoryLocks || this.disableLocks) {
272277
return
273278
}
274279

0 commit comments

Comments
 (0)
Please sign in to comment.