Skip to content
This repository was archived by the owner on Dec 23, 2020. It is now read-only.

Commit 6d85238

Browse files
committed
Moved db out of configuration object
1 parent 5da7cb4 commit 6d85238

File tree

4 files changed

+9
-12
lines changed

4 files changed

+9
-12
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ async function runMigrations() {
2929
// (note that migrateInTransaction also accepts single connections, not only pools)
3030
let migrations = await migrateInTransaction(dbPool, async db => {
3131
let umzug = new Umzug({
32-
storage: new PGStorage({
33-
db: db, // required
32+
// second parameter (config) is entirely optional
33+
storage: new PGStorage(db, {
3434
tableName: "MyAppMigration", // optional (default is SchemaMigration)
3535
columnName: "MyAppRevisionID" // optional (default is RevisionID)
3636
}),
3737
migrations: {
38+
// passes the db connection to use to the first parameter of all the up()/down() migrations
39+
// you defined for umzug to run
3840
params: [db]
3941
}
4042
});

lib/index.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { Storage } from 'umzug';
33
import { ident } from 'pg-escape';
44

55
export interface PGStorageConfiguration {
6-
db: ClientBase;
76
tableName: string;
87
columnName: string;
98
}
109

1110
const configDefaults: PGStorageConfiguration = {
12-
db: undefined!,
1311
tableName: 'SchemaMigration',
1412
columnName: 'RevisionID'
1513
};
@@ -19,12 +17,9 @@ export class PGStorage implements Storage {
1917
private readonly config: PGStorageConfiguration;
2018
private tableCreated = false;
2119

22-
public constructor(partialConfig: Partial<PGStorageConfiguration> = {}) {
23-
this.config = Object.assign(partialConfig, configDefaults);
24-
this.db = this.config.db;
25-
if (this.db == null) {
26-
throw new Error('PGStorage requires a db connection or connection pool to be specified');
27-
}
20+
public constructor(db: ClientBase, partialConfig: Partial<PGStorageConfiguration> = {}) {
21+
this.db = db;
22+
this.config = Object.assign({}, partialConfig, configDefaults);
2823
}
2924

3025
private async createTable(): Promise<void> {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@robotty/umzug-postgres-storage",
3-
"version": "1.0.6",
3+
"version": "2.0.0",
44
"description": "PostgreSQL connector for umzug",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)