New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ovotech/pg-sql-migrate

Package Overview
Dependencies
Maintainers
145
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ovotech/pg-sql-migrate - npm Package Compare versions

Comparing version

to
3.2.0

1

dist/migrate.d.ts

@@ -16,2 +16,3 @@ /// <reference types="node" />

}) => Promise<string[]>;
export declare const isTransactionDisabled: (migration: string) => boolean;
export declare const executeMigrations: ({ db, table, logger, migrations, }: {

@@ -18,0 +19,0 @@ db: MigrationClient;

20

dist/migrate.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrate = exports.readAndExecuteMigrations = exports.loadConfig = exports.readNewMigrations = exports.executeMigrations = exports.readExecutedIds = exports.readMigrations = exports.filenameParts = void 0;
exports.migrate = exports.readAndExecuteMigrations = exports.loadConfig = exports.readNewMigrations = exports.executeMigrations = exports.isTransactionDisabled = exports.readExecutedIds = exports.readMigrations = exports.filenameParts = void 0;
const config_file_1 = require("@ovotech/config-file");

@@ -28,2 +28,3 @@ const pg_1 = require("pg");

};
exports.isTransactionDisabled = (migration) => migration.startsWith('-- pg-sql-migrate: DISABLE TRANSACTION');
exports.executeMigrations = async ({ db, table, logger, migrations, }) => {

@@ -33,10 +34,17 @@ for (const migration of migrations) {

logger.info(`Executing [${migration.id}] ${migration.name}`);
await db.query('BEGIN');
await db.query(migration.content);
await db.query(`INSERT INTO ${db.escapeIdentifier(table)} VALUES ($1);`, [migration.id]);
await db.query('COMMIT');
if (exports.isTransactionDisabled(migration.content)) {
await db.query(migration.content);
}
else {
await db.query('BEGIN');
await db.query(migration.content);
await db.query(`INSERT INTO ${db.escapeIdentifier(table)} VALUES ($1);`, [migration.id]);
await db.query('COMMIT');
}
}
catch (error) {
try {
await db.query('ROLLBACK');
if (!exports.isTransactionDisabled(migration.content)) {
await db.query('ROLLBACK');
}
}

@@ -43,0 +51,0 @@ finally {

@@ -5,3 +5,3 @@ {

"repository": "git@github.com:ovotech/pg-sql-migrate.git",
"version": "3.1.0",
"version": "3.2.0",
"main": "dist/index.js",

@@ -8,0 +8,0 @@ "types": "dist/index.d.ts",

@@ -107,2 +107,11 @@ # Postgres migration tool with plain sql

## Distabling transactions for some migrations
By default migrations are wrapped in transactions, but there are some PG operations that cannot be performed inside a transaction. You can disable this for a specific transaction by adding a prefix
```sql
-- pg-sql-migrate: DISABLE TRANSACTION
ALTER TYPE my_type ADD VALUE 'VAL2' AFTER 'VAL1';
```
## Running the tests

@@ -109,0 +118,0 @@

@@ -49,2 +49,5 @@ import { loadConfigFile } from '@ovotech/config-file';

export const isTransactionDisabled = (migration: string): boolean =>
migration.startsWith('-- pg-sql-migrate: DISABLE TRANSACTION');
export const executeMigrations = async ({

@@ -64,9 +67,15 @@ db,

logger.info(`Executing [${migration.id}] ${migration.name}`);
await db.query('BEGIN');
await db.query(migration.content);
await db.query(`INSERT INTO ${db.escapeIdentifier(table)} VALUES ($1);`, [migration.id]);
await db.query('COMMIT');
if (isTransactionDisabled(migration.content)) {
await db.query(migration.content);
} else {
await db.query('BEGIN');
await db.query(migration.content);
await db.query(`INSERT INTO ${db.escapeIdentifier(table)} VALUES ($1);`, [migration.id]);
await db.query('COMMIT');
}
} catch (error) {
try {
await db.query('ROLLBACK');
if (!isTransactionDisabled(migration.content)) {
await db.query('ROLLBACK');
}
} finally {

@@ -73,0 +82,0 @@ throw new MigrationError(error.message, migration);

Sorry, the diff of this file is not supported yet