@contember/database-migrations
Advanced tools
Comparing version 0.12.0-beta.2 to 1.0.0-alpha.0
import { DatabaseCredentials } from '@contember/database'; | ||
import { ClientBase } from 'pg'; | ||
import { Migration } from './runner'; | ||
export declare class MigrationsRunner { | ||
export declare class MigrationsRunner<MigrationArgs> { | ||
private readonly db; | ||
@@ -10,3 +10,3 @@ private readonly schema; | ||
constructor(db: DatabaseCredentials, schema: string, migrations: () => Promise<Migration[]>, dbClient?: ClientBase | undefined); | ||
migrate<MigrationArgs>(log: (msg: string) => void, migrationArgs?: MigrationArgs): Promise<{ | ||
migrate(log: (msg: string) => void, migrationArgs?: MigrationArgs): Promise<{ | ||
name: string; | ||
@@ -13,0 +13,0 @@ }[]>; |
@@ -47,3 +47,3 @@ "use strict"; | ||
async createDatabaseIfNotExists(log) { | ||
await helpers_1.createDatabaseIfNotExists(this.db, log); | ||
await (0, helpers_1.createDatabaseIfNotExists)(this.db, log); | ||
} | ||
@@ -50,0 +50,0 @@ } |
@@ -72,6 +72,6 @@ "use strict"; | ||
const loadMigrations = async (sqlDir, additional) => { | ||
return (await Promise.all((await promises_1.readdir(sqlDir)) | ||
return (await Promise.all((await (0, promises_1.readdir)(sqlDir)) | ||
.filter(it => path_1.default.extname(it) === '.sql') | ||
.map(async (it) => { | ||
const migration = (await sqlMigration_1.default(path_1.join(sqlDir, it))).up; | ||
const migration = (await (0, sqlMigration_1.default)((0, path_1.join)(sqlDir, it))).up; | ||
if (!migration) { | ||
@@ -98,3 +98,3 @@ throw new Error(); | ||
const { migrationsTable } = options; | ||
return utils_1.createSchemalize(false, true)({ | ||
return (0, utils_1.createSchemalize)(false, true)({ | ||
schema, | ||
@@ -110,2 +110,5 @@ name: migrationsTable, | ||
catch (err) { | ||
if (!(err instanceof Error)) { | ||
throw err; | ||
} | ||
throw new Error(`Unable to ensure migrations table: ${err.stack}`); | ||
@@ -146,3 +149,3 @@ } | ||
const logger = getLogger(options); | ||
const db = db_1.default(options.dbClient || options.databaseUrl, logger); | ||
const db = (0, db_1.default)(options.dbClient || options.databaseUrl, logger); | ||
try { | ||
@@ -152,3 +155,3 @@ await db.createConnection(); | ||
if (options.schema) { | ||
const schemas = utils_1.getSchemas(options.schema); | ||
const schemas = (0, utils_1.getSchemas)(options.schema); | ||
if (options.createSchema) { | ||
@@ -176,3 +179,3 @@ await Promise.all(schemas.map(schema => db.query(`CREATE SCHEMA IF NOT EXISTS "${schema}"`))); | ||
logger.info(` Executing migration ${migration.name}...`); | ||
const migrationsBuilder = helpers_1.createMigrationBuilder(); | ||
const migrationsBuilder = (0, helpers_1.createMigrationBuilder)(); | ||
await migration.migration(migrationsBuilder, options.migrationArgs); | ||
@@ -179,0 +182,0 @@ const steps = migrationsBuilder.getSqlSteps(); |
{ | ||
"name": "@contember/database-migrations", | ||
"version": "0.12.0-beta.2", | ||
"version": "1.0.0-alpha.0", | ||
"scripts": { | ||
@@ -11,3 +11,3 @@ "test": "echo 'No tests'" | ||
"dependencies": { | ||
"@contember/database": "^0.12.0-beta.2", | ||
"@contember/database": "^1.0.0-alpha.0", | ||
"node-pg-migrate": "^5.9.0" | ||
@@ -14,0 +14,0 @@ }, |
@@ -7,3 +7,3 @@ import { DatabaseCredentials } from '@contember/database' | ||
export class MigrationsRunner { | ||
export class MigrationsRunner<MigrationArgs> { | ||
constructor( | ||
@@ -16,3 +16,3 @@ private readonly db: DatabaseCredentials, | ||
public async migrate<MigrationArgs>( | ||
public async migrate( | ||
log: (msg: string) => void, | ||
@@ -19,0 +19,0 @@ migrationArgs?: MigrationArgs, |
@@ -116,2 +116,5 @@ /* | ||
} catch (err) { | ||
if (!(err instanceof Error)) { | ||
throw err | ||
} | ||
throw new Error(`Unable to ensure migrations table: ${err.stack}`) | ||
@@ -118,0 +121,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80936
668
+ Added@contember/database@1.4.6(transitive)
+ Added@contember/queryable@1.4.6(transitive)
- Removed@contember/database@0.12.0-beta.2(transitive)
- Removed@contember/queryable@0.12.0-beta.2(transitive)