@contember/database-migrations
Advanced tools
Comparing version 1.4.0-rc.8 to 2.0.0-alpha.8
{ | ||
"name": "@contember/database-migrations", | ||
"version": "1.4.0-rc.8", | ||
"scripts": { | ||
"test": "vitest --dir ./tests/cases" | ||
}, | ||
"version": "2.0.0-alpha.8", | ||
"license": "Apache-2.0", | ||
"main": "dist/src/index.js", | ||
"typings": "dist/src/index.d.ts", | ||
"main": "./dist/production/index.js", | ||
"typings": "./dist/types/index.d.ts", | ||
"exports": { | ||
"typescript": "./src/index.ts", | ||
"default": "./dist/src/index.js" | ||
".": { | ||
"import": { | ||
"types": "./dist/types/index.d.ts", | ||
"development": "./dist/development/index.js", | ||
"production": "./dist/production/index.js", | ||
"typescript": "./src/index.ts", | ||
"default": "./dist/production/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/types/index.d.ts", | ||
"development": "./dist/development/index.cjs", | ||
"production": "./dist/production/index.cjs", | ||
"typescript": "./src/index.ts", | ||
"default": "./dist/production/index.cjs" | ||
} | ||
} | ||
}, | ||
"dependencies": { | ||
"@contember/database": "1.4.0-rc.8", | ||
"@contember/database": "2.0.0-alpha.8", | ||
"node-pg-migrate": "^5.10.0" | ||
@@ -23,3 +34,4 @@ }, | ||
"pg": "^8.9.0" | ||
} | ||
}, | ||
"type": "module" | ||
} |
import { MigrationBuilder } from 'node-pg-migrate' | ||
import { Migration, RunMigration } from './Migration' | ||
import MigrationBuilderImpl from 'node-pg-migrate/dist/migration-builder.js' | ||
import { escapeValue as pgEscape } from 'node-pg-migrate/dist/utils.js' | ||
export function createMigrationBuilder(): MigrationBuilder & { getSql: () => string; getSqlSteps: () => string[] } { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const builderClass = require('node-pg-migrate/dist/migration-builder').default | ||
return new builderClass( | ||
{}, | ||
const impl = 'default' in MigrationBuilderImpl ? (MigrationBuilderImpl as any).default : MigrationBuilderImpl | ||
return new impl( | ||
{ | ||
query: null, | ||
select: null, | ||
}, | ||
} as any, | ||
{}, | ||
false, | ||
{} as any, | ||
) | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const pgEscape = require('node-pg-migrate/dist/utils').escapeValue | ||
export function escapeValue(value: any): any { | ||
@@ -20,0 +20,0 @@ return pgEscape(value) |
@@ -7,3 +7,3 @@ export * from './MigrationsRunner' | ||
export * from './MigrationsResolver' | ||
export { MigrationBuilder, Name } from 'node-pg-migrate' | ||
export { DatabaseConfig } from '@contember/database' | ||
export type { MigrationBuilder, Name } from 'node-pg-migrate' | ||
export type { DatabaseConfig } from '@contember/database' |
@@ -55,3 +55,3 @@ /* | ||
CREATE TABLE IF NOT EXISTS ${fullTableName} ( | ||
id SERIAL PRIMARY KEY, | ||
id INT PRIMARY KEY, | ||
name varchar(255) NOT NULL, | ||
@@ -62,2 +62,10 @@ run_on timestamp NOT NULL | ||
await db.query(`ALTER TABLE ${fullTableName} ADD COLUMN IF NOT EXISTS "group" TEXT DEFAULT NULL`) | ||
await db.query(`ALTER TABLE ${fullTableName} ALTER id DROP DEFAULT`) | ||
const seqName = (await db.query<{seq_name: string}>(` | ||
SELECT pg_get_serial_sequence('${fullTableName}', 'id') as seq_name | ||
`)).rows[0].seq_name | ||
if (seqName) { | ||
await db.query(`DROP SEQUENCE ${seqName}`) | ||
} | ||
} catch (err) { | ||
@@ -117,6 +125,7 @@ if (!(err instanceof Error)) { | ||
} | ||
const maxId = await trx.query<{id: number}>(`SELECT MAX(id) as id FROM ${getMigrationsTableName(options)}`) | ||
const nextId = (maxId.rows[0]?.id ?? 0) + 1 | ||
await trx.query( | ||
`INSERT INTO ${getMigrationsTableName(options)} (name, run_on, "group") VALUES (?, NOW(), ?);`, | ||
[migration.name, migration.group], | ||
`INSERT INTO ${getMigrationsTableName(options)} (id, name, run_on, "group") VALUES (?, ?, NOW(), ?);`, | ||
[nextId, migration.name, migration.group], | ||
) | ||
@@ -123,0 +132,0 @@ logger(` Done`) |
{ | ||
"extends": "../tsconfig.settings.json", | ||
"compilerOptions": { | ||
"outDir": "../dist/src" | ||
"outDir": "../dist/types" | ||
}, | ||
@@ -6,0 +6,0 @@ "references": [ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
211596
89
1643
Yes
5
1
+ Added@contember/database@2.0.0-alpha.8(transitive)
+ Added@contember/queryable@2.0.0-alpha.8(transitive)
- Removed@contember/database@1.4.0-rc.8(transitive)
- Removed@contember/queryable@1.4.0-rc.8(transitive)