Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contember/database-migrations

Package Overview
Dependencies
Maintainers
0
Versions
247
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contember/database-migrations - npm Package Compare versions

Comparing version 1.4.0-rc.8 to 2.0.0-alpha.8

dist/development/index.cjs

32

package.json
{
"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": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc