Socket
Socket
Sign inDemoInstall

node-pg-migrate

Package Overview
Dependencies
57
Maintainers
3
Versions
167
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.0-alpha.3 to 7.0.0-alpha.4

dist/migrationBuilder.d.ts

10

dist/db.js

@@ -1,3 +0,3 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _pg = require('pg');
var _util = require('util');
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _nodeutil = require('node:util');
var _pg = require('pg');
var ConnectionStatus = /* @__PURE__ */ ((ConnectionStatus2) => {

@@ -25,3 +25,3 @@ ConnectionStatus2["DISCONNECTED"] = "DISCONNECTED";

connectionStatus = "ERROR" /* ERROR */;
logger.error(`could not connect to postgres: ${_util.inspect.call(void 0, err)}`);
logger.error(`could not connect to postgres: ${_nodeutil.inspect.call(void 0, err)}`);
reject(err);

@@ -45,4 +45,4 @@ return;

const endLineWrapPos = endLineWrapIndexOf >= 0 ? endLineWrapIndexOf : string.length;
const stringStart = string.substring(0, endLineWrapPos);
const stringEnd = string.substr(endLineWrapPos);
const stringStart = string.slice(0, endLineWrapPos);
const stringEnd = string.slice(endLineWrapPos);
const startLineWrapPos = stringStart.lastIndexOf("\n") + 1;

@@ -49,0 +49,0 @@ const padding = " ".repeat(position - startLineWrapPos - 1);

@@ -5,3 +5,3 @@ export { Migration } from './migration';

export type { CreateFunction, CreateFunctionFn, DropFunction, FunctionOptions, FunctionParam, FunctionParamType, RenameFunction, RenameFunctionFn, } from './operations/functions';
export type { CascadeOption, DropOptions, IfExistsOption, IfNotExistsOption, Name, Type, Value, } from './operations/generalTypes';
export type { CascadeOption, DropOptions, IfExistsOption, IfNotExistsOption, LiteralUnion, Name, Nullable, Operation, OperationFn, PublicPart, Reversible, Type, Value, } from './operations/generalTypes';
export type { CreateIndex, CreateIndexFn, CreateIndexOptions, DropIndex, DropIndexOptions, IndexColumn, } from './operations/indexes';

@@ -8,0 +8,0 @@ export type { AlterMaterializedView, AlterMaterializedViewOptions, CreateMaterializedView, CreateMaterializedViewFn, CreateMaterializedViewOptions, DropMaterializedView, RefreshMaterializedView, RefreshMaterializedViewFn, RefreshMaterializedViewOptions, RenameMaterializedView, RenameMaterializedViewColumn, RenameMaterializedViewColumnFn, RenameMaterializedViewFn, StorageParameters, } from './operations/materializedViews';

import type { QueryResult } from 'pg';
import type { DBConnection } from './db';
import MigrationBuilder from './migration-builder';
import MigrationBuilder from './migrationBuilder';
import type { ColumnDefinitions } from './operations/tables';

@@ -25,4 +25,4 @@ import type { Logger, MigrationAction, MigrationBuilderActions, MigrationDirection, RunnerOption } from './types';

} & (CreateOptionsTemplate | CreateOptionsDefault);
export declare const loadMigrationFiles: (dir: string, ignorePattern?: string) => Promise<string[]>;
export declare const getTimestamp: (logger: Logger, filename: string) => number;
export declare function loadMigrationFiles(dir: string, ignorePattern?: string): Promise<string[]>;
export declare function getTimestamp(logger: Logger, filename: string): number;
export declare class Migration implements RunMigration {

@@ -29,0 +29,0 @@ static create(name: string, directory: string, options?: CreateOptions): Promise<string>;

@@ -1,7 +0,6 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
var _mkdirp = require('mkdirp'); var _mkdirp2 = _interopRequireDefault(_mkdirp);
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
var _migrationbuilder = require('./migration-builder'); var _migrationbuilder2 = _interopRequireDefault(_migrationbuilder);
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _nodefs = require('node:fs');
var _promises = require('node:fs/promises');
var _nodepath = require('node:path');
var _migrationBuilder = require('./migrationBuilder'); var _migrationBuilder2 = _interopRequireDefault(_migrationBuilder);
var _utils = require('./utils');
const { readdir } = _fs2.default.promises;
var FilenameFormat = /* @__PURE__ */ ((FilenameFormat2) => {

@@ -13,10 +12,12 @@ FilenameFormat2["timestamp"] = "timestamp";

const SEPARATOR = "_";
const loadMigrationFiles = async (dir, ignorePattern) => {
const dirContent = await readdir(`${dir}/`, { withFileTypes: true });
async function loadMigrationFiles(dir, ignorePattern) {
const dirContent = await _promises.readdir.call(void 0, `${dir}/`, { withFileTypes: true });
const files = dirContent.map((file) => file.isFile() || file.isSymbolicLink() ? file.name : null).filter((file) => Boolean(file)).sort();
const filter = new RegExp(`^(${ignorePattern})$`);
return ignorePattern === void 0 ? files : files.filter((i) => !filter.test(i));
};
const getSuffixFromFileName = (fileName) => _path2.default.extname(fileName).substr(1);
const getLastSuffix = async (dir, ignorePattern) => {
}
function getSuffixFromFileName(fileName) {
return _nodepath.extname.call(void 0, fileName).slice(1);
}
async function getLastSuffix(dir, ignorePattern) {
try {

@@ -28,4 +29,4 @@ const files = await loadMigrationFiles(dir, ignorePattern);

}
};
const getTimestamp = (logger, filename) => {
}
function getTimestamp(logger, filename) {
const prefix = filename.split(SEPARATOR)[0];

@@ -37,9 +38,9 @@ if (prefix && /^\d+$/.test(prefix)) {

if (prefix && prefix.length === 17) {
const year = prefix.substr(0, 4);
const month = prefix.substr(4, 2);
const date = prefix.substr(6, 2);
const hours = prefix.substr(8, 2);
const minutes = prefix.substr(10, 2);
const seconds = prefix.substr(12, 2);
const ms = prefix.substr(14);
const year = prefix.slice(0, 4);
const month = prefix.slice(4, 6);
const date = prefix.slice(6, 8);
const hours = prefix.slice(8, 10);
const minutes = prefix.slice(10, 12);
const seconds = prefix.slice(12, 14);
const ms = prefix.slice(14, 17);
return (/* @__PURE__ */ new Date(

@@ -52,4 +53,6 @@ `${year}-${month}-${date}T${hours}:${minutes}:${seconds}.${ms}Z`

return Number(prefix) || 0;
};
const resolveSuffix = async (directory, { language, ignorePattern }) => language || await getLastSuffix(directory, ignorePattern) || "js";
}
async function resolveSuffix(directory, { language, ignorePattern }) {
return language || await getLastSuffix(directory, ignorePattern) || "js";
}
class Migration {

@@ -59,6 +62,6 @@ // class method that creates a new migration file by cloning the migration template

const { filenameFormat = "timestamp" /* timestamp */ } = options;
_mkdirp2.default.sync(directory);
await _promises.mkdir.call(void 0, directory, { recursive: true });
const now = /* @__PURE__ */ new Date();
const time = filenameFormat === "utc" /* utc */ ? now.toISOString().replace(/[^\d]/g, "") : now.valueOf();
const templateFileName = "templateFileName" in options ? _path2.default.resolve(process.cwd(), options.templateFileName) : _path2.default.resolve(
const templateFileName = "templateFileName" in options ? _nodepath.resolve.call(void 0, process.cwd(), options.templateFileName) : _nodepath.resolve.call(void 0,
__dirname,

@@ -69,4 +72,4 @@ `../templates/migration-template.${await resolveSuffix(directory, options)}`

const newFile = `${directory}/${time}${SEPARATOR}${name}.${suffix}`;
await new Promise((resolve, reject) => {
_fs2.default.createReadStream(templateFileName).pipe(_fs2.default.createWriteStream(newFile)).on("close", resolve).on("error", reject);
await new Promise((resolve2, reject) => {
_nodefs.createReadStream.call(void 0, templateFileName).pipe(_nodefs.createWriteStream.call(void 0, newFile)).on("close", resolve2).on("error", reject);
});

@@ -78,3 +81,3 @@ return newFile;

this.path = migrationPath;
this.name = _path2.default.basename(migrationPath, _path2.default.extname(migrationPath));
this.name = _nodepath.basename.call(void 0, migrationPath, _nodepath.extname.call(void 0, migrationPath));
this.timestamp = getTimestamp(logger, this.name);

@@ -107,4 +110,4 @@ this.up = up;

if (action.length === 2) {
await new Promise((resolve) => {
action(pgm, resolve);
await new Promise((resolve2) => {
action(pgm, resolve2);
});

@@ -156,3 +159,3 @@ } else {

apply(direction) {
const pgm = new (0, _migrationbuilder2.default)(
const pgm = new (0, _migrationBuilder2.default)(
this.db,

@@ -159,0 +162,0 @@ this.typeShorthands,

import type { MigrationOptions } from '../../types';
import type { DropOptions, Name, Type } from '../generalTypes';
import type { DropOptions, Name, Reversible, Type } from '../generalTypes';
import type { DomainOptions } from './shared';

@@ -8,5 +8,3 @@ export interface DomainOptionsCreate extends DomainOptions {

export declare type CreateDomainFn = (domainName: Name, type: Type, domainOptions?: DomainOptionsCreate & DropOptions) => string | string[];
export declare type CreateDomain = CreateDomainFn & {
reverse: CreateDomainFn;
};
export declare type CreateDomain = Reversible<CreateDomainFn>;
export declare function createDomain(mOptions: MigrationOptions): CreateDomain;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameDomainFn = (oldDomainName: Name, newDomainName: Name) => string | string[];
export declare type RenameDomain = RenameDomainFn & {
reverse: RenameDomainFn;
};
export declare type RenameDomain = Reversible<RenameDomainFn>;
export declare function renameDomain(mOptions: MigrationOptions): RenameDomain;
import type { MigrationOptions } from '../../types';
import type { DropOptions, IfNotExistsOption } from '../generalTypes';
import type { DropOptions, IfNotExistsOption, Reversible } from '../generalTypes';
import type { StringExtension } from './shared';

@@ -8,5 +8,3 @@ export interface CreateExtensionOptions extends IfNotExistsOption {

export declare type CreateExtensionFn = (extension: StringExtension | StringExtension[], options?: CreateExtensionOptions & DropOptions) => string | string[];
export declare type CreateExtension = CreateExtensionFn & {
reverse: CreateExtensionFn;
};
export declare type CreateExtension = Reversible<CreateExtensionFn>;
export declare function createExtension(mOptions: MigrationOptions): CreateExtension;
import type { MigrationOptions } from '../../types';
import type { DropOptions, Name, Value } from '../generalTypes';
import type { DropOptions, Name, Reversible, Value } from '../generalTypes';
import type { FunctionOptions, FunctionParam } from './shared';
export declare type CreateFunctionFn = (functionName: Name, functionParams: FunctionParam[], functionOptions: FunctionOptions & DropOptions, definition: Value) => string | string[];
export declare type CreateFunction = CreateFunctionFn & {
reverse: CreateFunctionFn;
};
export declare type CreateFunction = Reversible<CreateFunctionFn>;
export declare function createFunction(mOptions: MigrationOptions): CreateFunction;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
import type { FunctionParam } from './shared';
export declare type RenameFunctionFn = (oldFunctionName: Name, functionParams: FunctionParam[], newFunctionName: Name) => string | string[];
export declare type RenameFunction = RenameFunctionFn & {
reverse: RenameFunctionFn;
};
export declare type RenameFunction = Reversible<RenameFunctionFn>;
export declare function renameFunction(mOptions: MigrationOptions): RenameFunction;

@@ -34,1 +34,36 @@ import type { PgLiteral, PgLiteralValue } from '../utils';

export declare type DropOptions = IfExistsOption & CascadeOption;
/**
* A function that returns a normal SQL statement or an array of SQL statements.
*
* The array is useful for operations that need to return multiple SQL statements like an additional `COMMENT`.
*/
export declare type OperationFn = (...args: any[]) => string | string[];
/**
* A function that returns a normal SQL statement or an array of SQL statements.
*
* The array is useful for operations that need to return multiple SQL statements like an additional `COMMENT`.
*
* The `reverse` property is a function that takes the same arguments and try to infer the reverse SQL statement with that.
*/
export declare type Operation = OperationFn & {
/**
* Reverse the operation if provided.
*/
reverse?: OperationFn;
};
/**
* A function that returns a normal SQL statement or an array of SQL statements.
*
* The array is useful for operations that need to return multiple SQL statements like an additional `COMMENT`.
*
* The `reverse` property is a function that takes the same arguments and try to infer the reverse SQL statement with that.
*/
export declare type Reversible<TFunction extends (...args: any[]) => string | string[]> = TFunction & {
/**
* Reverse the operation.
*
* Needs to be the same function definition, because it takes the same
* arguments and try to infer the reverse SQL statement with that.
*/
reverse: TFunction;
};
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
import type { DropIndexOptions } from './dropIndex';

@@ -19,5 +19,3 @@ import type { IndexColumn } from './shared';

export declare type CreateIndexFn = (tableName: Name, columns: string | Array<string | IndexColumn>, options?: CreateIndexOptions & DropIndexOptions) => string | string[];
export declare type CreateIndex = CreateIndexFn & {
reverse: CreateIndexFn;
};
export declare type CreateIndex = Reversible<CreateIndexFn>;
export declare function createIndex(mOptions: MigrationOptions): CreateIndex;
import type { MigrationOptions } from '../../types';
import type { DropOptions, IfNotExistsOption, Name } from '../generalTypes';
import type { DropOptions, IfNotExistsOption, Name, Reversible } from '../generalTypes';
import type { StorageParameters } from './shared';

@@ -11,5 +11,3 @@ export interface CreateMaterializedViewOptions extends IfNotExistsOption {

export declare type CreateMaterializedViewFn = (viewName: Name, options: CreateMaterializedViewOptions & DropOptions, definition: string) => string | string[];
export declare type CreateMaterializedView = CreateMaterializedViewFn & {
reverse: CreateMaterializedViewFn;
};
export declare type CreateMaterializedView = Reversible<CreateMaterializedViewFn>;
export declare function createMaterializedView(mOptions: MigrationOptions): CreateMaterializedView;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export interface RefreshMaterializedViewOptions {

@@ -8,5 +8,3 @@ concurrently?: boolean;

export declare type RefreshMaterializedViewFn = (viewName: Name, options?: RefreshMaterializedViewOptions) => string | string[];
export declare type RefreshMaterializedView = RefreshMaterializedViewFn & {
reverse: RefreshMaterializedViewFn;
};
export declare type RefreshMaterializedView = Reversible<RefreshMaterializedViewFn>;
export declare function refreshMaterializedView(mOptions: MigrationOptions): RefreshMaterializedView;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameMaterializedViewFn = (viewName: Name, newViewName: Name) => string | string[];
export declare type RenameMaterializedView = RenameMaterializedViewFn & {
reverse: RenameMaterializedViewFn;
};
export declare type RenameMaterializedView = Reversible<RenameMaterializedViewFn>;
export declare function renameMaterializedView(mOptions: MigrationOptions): RenameMaterializedView;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameMaterializedViewColumnFn = (viewName: Name, columnName: string, newColumnName: string) => string | string[];
export declare type RenameMaterializedViewColumn = RenameMaterializedViewColumnFn & {
reverse: RenameMaterializedViewColumnFn;
};
export declare type RenameMaterializedViewColumn = Reversible<RenameMaterializedViewColumnFn>;
export declare function renameMaterializedViewColumn(mOptions: MigrationOptions): RenameMaterializedViewColumn;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
import type { OperatorListDefinition } from './shared';
export declare type AddToOperatorFamilyFn = (operatorFamilyName: Name, indexMethod: Name, operatorList: OperatorListDefinition[]) => string | string[];
export declare type AddToOperatorFamily = AddToOperatorFamilyFn & {
reverse: AddToOperatorFamilyFn;
};
export declare type AddToOperatorFamily = Reversible<AddToOperatorFamilyFn>;
export declare const addToOperatorFamily: (mOptions: MigrationOptions) => AddToOperatorFamily;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
import type { DropOperatorOptions } from './dropOperator';

@@ -16,5 +16,3 @@ export interface CreateOperatorOptions {

export declare type CreateOperatorFn = (operatorName: Name, options: CreateOperatorOptions & DropOperatorOptions) => string | string[];
export declare type CreateOperator = CreateOperatorFn & {
reverse: CreateOperatorFn;
};
export declare type CreateOperator = Reversible<CreateOperatorFn>;
export declare function createOperator(mOptions: MigrationOptions): CreateOperator;
import type { MigrationOptions } from '../../types';
import type { DropOptions, Name, Type } from '../generalTypes';
import type { DropOptions, Name, Reversible, Type } from '../generalTypes';
import type { OperatorListDefinition } from './shared';

@@ -9,5 +9,3 @@ export interface CreateOperatorClassOptions {

export declare type CreateOperatorClassFn = (operatorClassName: Name, type: Type, indexMethod: Name, operatorList: OperatorListDefinition[], options: CreateOperatorClassOptions & DropOptions) => string | string[];
export declare type CreateOperatorClass = CreateOperatorClassFn & {
reverse: CreateOperatorClassFn;
};
export declare type CreateOperatorClass = Reversible<CreateOperatorClassFn>;
export declare function createOperatorClass(mOptions: MigrationOptions): CreateOperatorClass;
import type { MigrationOptions } from '../../types';
import type { DropOptions, Name } from '../generalTypes';
import type { DropOptions, Name, Reversible } from '../generalTypes';
export declare type CreateOperatorFamilyFn = (operatorFamilyName: Name, indexMethod: Name, options?: DropOptions) => string | string[];
export declare type CreateOperatorFamily = CreateOperatorFamilyFn & {
reverse: CreateOperatorFamilyFn;
};
export declare type CreateOperatorFamily = Reversible<CreateOperatorFamilyFn>;
export declare function createOperatorFamily(mOptions: MigrationOptions): CreateOperatorFamily;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameOperatorClassFn = (oldOperatorClassName: Name, indexMethod: Name, newOperatorClassName: Name) => string | string[];
export declare type RenameOperatorClass = RenameOperatorClassFn & {
reverse: RenameOperatorClassFn;
};
export declare type RenameOperatorClass = Reversible<RenameOperatorClassFn>;
export declare function renameOperatorClass(mOptions: MigrationOptions): RenameOperatorClass;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameOperatorFamilyFn = (oldOperatorFamilyName: Name, indexMethod: Name, newOperatorFamilyName: Name) => string | string[];
export declare type RenameOperatorFamily = RenameOperatorFamilyFn & {
reverse: RenameOperatorFamilyFn;
};
export declare type RenameOperatorFamily = Reversible<RenameOperatorFamilyFn>;
export declare function renameOperatorFamily(mOptions: MigrationOptions): RenameOperatorFamily;
import type { MigrationOptions } from '../../types';
import type { IfExistsOption, Name } from '../generalTypes';
import type { IfExistsOption, Name, Reversible } from '../generalTypes';
import type { PolicyOptions } from './shared';

@@ -9,6 +9,4 @@ export interface CreatePolicyOptionsEn {

declare type CreatePolicyFn = (tableName: Name, policyName: string, options?: CreatePolicyOptions & IfExistsOption) => string | string[];
export declare type CreatePolicy = CreatePolicyFn & {
reverse: CreatePolicyFn;
};
export declare type CreatePolicy = Reversible<CreatePolicyFn>;
export declare function createPolicy(mOptions: MigrationOptions): CreatePolicy;
export {};
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenamePolicyFn = (tableName: Name, policyName: string, newPolicyName: string) => string | string[];
export declare type RenamePolicy = RenamePolicyFn & {
reverse: RenamePolicyFn;
};
export declare type RenamePolicy = Reversible<RenamePolicyFn>;
export declare function renamePolicy(mOptions: MigrationOptions): RenamePolicy;
import type { MigrationOptions } from '../../types';
import type { IfExistsOption, Name } from '../generalTypes';
import type { IfExistsOption, Name, Reversible } from '../generalTypes';
import type { RoleOptions } from './shared';
export declare type CreateRoleFn = (roleName: Name, roleOptions?: RoleOptions & IfExistsOption) => string | string[];
export declare type CreateRole = CreateRoleFn & {
reverse: CreateRoleFn;
};
export declare type CreateRole = Reversible<CreateRoleFn>;
export declare function createRole(mOptions: MigrationOptions): CreateRole;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameRoleFn = (oldRoleName: Name, newRoleName: Name) => string | string[];
export declare type RenameRole = RenameRoleFn & {
reverse: RenameRoleFn;
};
export declare type RenameRole = Reversible<RenameRoleFn>;
export declare function renameRole(mOptions: MigrationOptions): RenameRole;
import type { MigrationOptions } from '../../types';
import type { DropOptions, IfNotExistsOption } from '../generalTypes';
import type { DropOptions, IfNotExistsOption, Reversible } from '../generalTypes';
export interface CreateSchemaOptions extends IfNotExistsOption {

@@ -7,5 +7,3 @@ authorization?: string;

export declare type CreateSchemaFn = (schemaName: string, schemaOptions?: CreateSchemaOptions & DropOptions) => string | string[];
export declare type CreateSchema = CreateSchemaFn & {
reverse: CreateSchemaFn;
};
export declare type CreateSchema = Reversible<CreateSchemaFn>;
export declare function createSchema(mOptions: MigrationOptions): CreateSchema;
import type { MigrationOptions } from '../../types';
import type { Reversible } from '../generalTypes';
export declare type RenameSchemaFn = (oldSchemaName: string, newSchemaName: string) => string | string[];
export declare type RenameSchema = RenameSchemaFn & {
reverse: RenameSchemaFn;
};
export declare type RenameSchema = Reversible<RenameSchemaFn>;
export declare function renameSchema(mOptions: MigrationOptions): RenameSchema;
import type { MigrationOptions } from '../../types';
import type { DropOptions, IfNotExistsOption, Name } from '../generalTypes';
import type { DropOptions, IfNotExistsOption, Name, Reversible } from '../generalTypes';
import type { SequenceOptions } from './shared';

@@ -8,5 +8,3 @@ export interface SequenceOptionsCreate extends SequenceOptions, IfNotExistsOption {

export declare type CreateSequenceFn = (sequenceName: Name, sequenceOptions?: SequenceOptionsCreate & DropOptions) => string | string[];
export declare type CreateSequence = CreateSequenceFn & {
reverse: CreateSequenceFn;
};
export declare type CreateSequence = Reversible<CreateSequenceFn>;
export declare function createSequence(mOptions: MigrationOptions): CreateSequence;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameSequenceFn = (oldSequenceName: Name, newSequenceName: Name) => string | string[];
export declare type RenameSequence = RenameSequenceFn & {
reverse: RenameSequenceFn;
};
export declare type RenameSequence = Reversible<RenameSequenceFn>;
export declare function renameSequence(mOptions: MigrationOptions): RenameSequence;
import type { MigrationOptions } from '../../types';
import type { DropOptions, IfNotExistsOption, Name } from '../generalTypes';
import type { DropOptions, IfNotExistsOption, Name, Reversible } from '../generalTypes';
import type { ColumnDefinitions } from './shared';
export declare type AddColumnsFn = (tableName: Name, newColumns: ColumnDefinitions, addOptions?: IfNotExistsOption & DropOptions) => string | string[];
export declare type AddColumns = AddColumnsFn & {
reverse: AddColumnsFn;
};
export declare type AddColumns = Reversible<AddColumnsFn>;
export declare function addColumns(mOptions: MigrationOptions): AddColumns;
import type { MigrationOptions } from '../../types';
import type { DropOptions, Name } from '../generalTypes';
import { type ConstraintOptions } from './shared';
export declare type CreateConstraintFn = (tableName: Name, constraintName: string | null, expression: (string | ConstraintOptions) & DropOptions) => string | string[];
export declare type CreateConstraint = CreateConstraintFn & {
reverse: CreateConstraintFn;
};
import type { DropOptions, Name, Reversible } from '../generalTypes';
import type { ConstraintOptions } from './shared';
export declare type CreateConstraintFn = (tableName: Name, constraintName: string | null, expression: string | (ConstraintOptions & DropOptions)) => string | string[];
export declare type CreateConstraint = Reversible<CreateConstraintFn>;
export declare function addConstraint(mOptions: MigrationOptions): CreateConstraint;

@@ -30,2 +30,7 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _utils = require('../../utils');

}
if (typeof options === "string") {
throw new Error(
"Impossible to automatically infer down migration for addConstraint with raw SQL expression"
);
}
return _dropConstraint.dropConstraint.call(void 0, mOptions)(tableName, constraintName, options);

@@ -32,0 +37,0 @@ };

import type { MigrationOptions } from '../../types';
import type { DropOptions, Name } from '../generalTypes';
import type { DropOptions, Name, Reversible } from '../generalTypes';
import type { ColumnDefinitions, TableOptions } from './shared';
export declare type CreateTableFn = (tableName: Name, columns: ColumnDefinitions, options?: TableOptions & DropOptions) => string | string[];
export declare type CreateTable = CreateTableFn & {
reverse: CreateTableFn;
};
export declare type CreateTable = Reversible<CreateTableFn>;
export declare function createTable(mOptions: MigrationOptions): CreateTable;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameColumnFn = (tableName: Name, oldColumnName: string, newColumnName: string) => string | string[];
export declare type RenameColumn = RenameColumnFn & {
reverse: RenameColumnFn;
};
export declare type RenameColumn = Reversible<RenameColumnFn>;
export declare function renameColumn(mOptions: MigrationOptions): RenameColumn;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameConstraintFn = (tableName: Name, oldConstraintName: string, newConstraintName: string) => string | string[];
export declare type RenameConstraint = RenameConstraintFn & {
reverse: RenameConstraintFn;
};
export declare type RenameConstraint = Reversible<RenameConstraintFn>;
export declare function renameConstraint(mOptions: MigrationOptions): RenameConstraint;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameTableFn = (tableName: Name, newtableName: Name) => string | string[];
export declare type RenameTable = RenameTableFn & {
reverse: RenameTableFn;
};
export declare type RenameTable = Reversible<RenameTableFn>;
export declare function renameTable(mOptions: MigrationOptions): RenameTable;
import type { MigrationOptions } from '../../types';
import type { FunctionOptions } from '../functions';
import type { DropOptions, Name, Value } from '../generalTypes';
import type { DropOptions, Name, Reversible, Value } from '../generalTypes';
import type { TriggerOptions } from './shared';

@@ -8,5 +8,3 @@ export declare type CreateTriggerFn1 = (tableName: Name, triggerName: string, triggerOptions: TriggerOptions & DropOptions) => string | string[];

export declare type CreateTriggerFn = CreateTriggerFn1 | CreateTriggerFn2;
export declare type CreateTrigger = CreateTriggerFn & {
reverse: CreateTriggerFn;
};
export declare type CreateTrigger = Reversible<CreateTriggerFn>;
export declare function createTrigger(mOptions: MigrationOptions): CreateTrigger;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameTriggerFn = (tableName: Name, oldTriggerName: string, newTriggerName: string) => string | string[];
export declare type RenameTrigger = RenameTriggerFn & {
reverse: RenameTriggerFn;
};
export declare type RenameTrigger = Reversible<RenameTriggerFn>;
export declare function renameTrigger(mOptions: MigrationOptions): RenameTrigger;
import type { MigrationOptions } from '../../types';
import type { IfExistsOption, Name, Type } from '../generalTypes';
import type { IfExistsOption, Name, Reversible, Type } from '../generalTypes';
export declare type AddTypeAttributeFn = (typeName: Name, attributeName: string, attributeType: Type & IfExistsOption) => string | string[];
export declare type AddTypeAttribute = AddTypeAttributeFn & {
reverse: AddTypeAttributeFn;
};
export declare type AddTypeAttribute = Reversible<AddTypeAttributeFn>;
export declare function addTypeAttribute(mOptions: MigrationOptions): AddTypeAttribute;
import type { MigrationOptions } from '../../types';
import type { DropOptions, Name, Type, Value } from '../generalTypes';
import type { DropOptions, Name, Reversible, Type, Value } from '../generalTypes';
export declare type CreateTypeFn = (typeName: Name, values: (Value[] | {
[name: string]: Type;
}) & DropOptions) => string | string[];
export declare type CreateType = CreateTypeFn & {
reverse: CreateTypeFn;
};
export declare type CreateType = Reversible<CreateTypeFn>;
export declare function createType(mOptions: MigrationOptions): CreateType;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameTypeFn = (typeName: Name, newTypeName: Name) => string | string[];
export declare type RenameType = RenameTypeFn & {
reverse: RenameTypeFn;
};
export declare type RenameType = Reversible<RenameTypeFn>;
export declare function renameType(mOptions: MigrationOptions): RenameType;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameTypeAttributeFn = (typeName: Name, attributeName: string, newAttributeName: string) => string | string[];
export declare type RenameTypeAttribute = RenameTypeAttributeFn & {
reverse: RenameTypeAttributeFn;
};
export declare type RenameTypeAttribute = Reversible<RenameTypeAttributeFn>;
export declare function renameTypeAttribute(mOptions: MigrationOptions): RenameTypeAttribute;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameTypeValueFn = (typeName: Name, value: string, newValue: string) => string | string[];
export declare type RenameTypeValue = RenameTypeValueFn & {
reverse: RenameTypeValueFn;
};
export declare type RenameTypeValue = Reversible<RenameTypeValueFn>;
export declare function renameTypeValue(mOptions: MigrationOptions): RenameTypeValue;
import type { MigrationOptions } from '../../types';
import type { DropOptions, Name } from '../generalTypes';
import type { DropOptions, Name, Reversible } from '../generalTypes';
import type { ViewOptions } from './shared';

@@ -13,5 +13,3 @@ export interface CreateViewOptions {

export declare type CreateViewFn = (viewName: Name, options: CreateViewOptions & DropOptions, definition: string) => string | string[];
export declare type CreateView = CreateViewFn & {
reverse: CreateViewFn;
};
export declare type CreateView = Reversible<CreateViewFn>;
export declare function createView(mOptions: MigrationOptions): CreateView;
import type { MigrationOptions } from '../../types';
import type { Name } from '../generalTypes';
import type { Name, Reversible } from '../generalTypes';
export declare type RenameViewFn = (viewName: Name, newViewName: Name) => string | string[];
export declare type RenameView = RenameViewFn & {
reverse: RenameViewFn;
};
export declare type RenameView = Reversible<RenameViewFn>;
export declare function renameView(mOptions: MigrationOptions): RenameView;

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _path = require('path'); var _path2 = _interopRequireDefault(_path);
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _nodepath = require('node:path');
var _db = require('./db'); var _db2 = _interopRequireDefault(_db);

@@ -17,3 +17,3 @@ var _migration = require('./migration');

const filePath = `${options.dir}/${file}`;
const actions = _path2.default.extname(filePath) === ".sql" ? await _sqlMigration2.default.call(void 0, filePath) : require(_path2.default.relative(__dirname, filePath));
const actions = _nodepath.extname.call(void 0, filePath) === ".sql" ? await _sqlMigration2.default.call(void 0, filePath) : require(_nodepath.relative.call(void 0, __dirname, filePath));
shorthands = { ...shorthands, ...actions.shorthands };

@@ -20,0 +20,0 @@ return new (0, _migration.Migration)(

@@ -1,4 +0,5 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
const { readFile } = _fs2.default.promises;
const createMigrationCommentRegex = (direction) => new RegExp(`^\\s*--[\\s-]*${direction}\\s+migration`, "im");
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _promises = require('node:fs/promises');
function createMigrationCommentRegex(direction) {
return new RegExp(`^\\s*--[\\s-]*${direction}\\s+migration`, "im");
}
const getActions = (content) => {

@@ -9,7 +10,7 @@ const upMigrationCommentRegex = createMigrationCommentRegex("up");

const downMigrationStart = content.search(downMigrationCommentRegex);
const upSql = upMigrationStart >= 0 ? content.substr(
const upSql = upMigrationStart >= 0 ? content.slice(
upMigrationStart,
downMigrationStart < upMigrationStart ? void 0 : downMigrationStart
) : content;
const downSql = downMigrationStart >= 0 ? content.substr(
const downSql = downMigrationStart >= 0 ? content.slice(
downMigrationStart,

@@ -28,3 +29,3 @@ upMigrationStart < downMigrationStart ? void 0 : upMigrationStart

var sqlMigration_default = async (sqlPath) => {
const content = await readFile(sqlPath, "utf-8");
const content = await _promises.readFile.call(void 0, sqlPath, "utf-8");
return getActions(content);

@@ -31,0 +32,0 @@ };

@@ -29,81 +29,517 @@ import type { ClientBase, ClientConfig, QueryArrayConfig, QueryArrayResult, QueryConfig, QueryResult } from 'pg';

export interface MigrationBuilder {
/**
* Install an extension.
*
* @alias addExtension
*
* @see https://www.postgresql.org/docs/current/sql-createextension.html
*/
createExtension: (...args: Parameters<extensions.CreateExtension>) => void;
/**
* Remove an extension.
*
* @see https://www.postgresql.org/docs/current/sql-dropextension.html
*/
dropExtension: (...args: Parameters<extensions.DropExtension>) => void;
/**
* Install an extension.
*
* @alias createExtension
*
* @see https://www.postgresql.org/docs/current/sql-createextension.html
*/
addExtension: (...args: Parameters<extensions.CreateExtension>) => void;
/**
* Define a new table.
*
* @see https://www.postgresql.org/docs/current/sql-createtable.html
*/
createTable: (...args: Parameters<tables.CreateTable>) => void;
/**
* Remove a table.
*
* @see https://www.postgresql.org/docs/current/sql-droptable.html
*/
dropTable: (...args: Parameters<tables.DropTable>) => void;
/**
* Rename a table.
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
renameTable: (...args: Parameters<tables.RenameTable>) => void;
/**
* Change the definition of a table.
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
alterTable: (...args: Parameters<tables.AlterTable>) => void;
/**
* Add columns to a table.
*
* @alias addColumn
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
addColumns: (...args: Parameters<tables.AddColumns>) => void;
/**
* Remove columns from a table.
*
* @alias dropColumn
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
dropColumns: (...args: Parameters<tables.DropColumns>) => void;
/**
* Rename a column.
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
renameColumn: (...args: Parameters<tables.RenameColumn>) => void;
/**
* Change the definition of a column.
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
alterColumn: (...args: Parameters<tables.AlterColumn>) => void;
/**
* Add a column to a table.
*
* @alias addColumns
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
addColumn: (...args: Parameters<tables.AddColumns>) => void;
/**
* Remove a column from a table.
*
* @alias dropColumns
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
dropColumn: (...args: Parameters<tables.DropColumns>) => void;
/**
* Add a constraint to a table.
*
* @alias createConstraint
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
addConstraint: (...args: Parameters<tables.CreateConstraint>) => void;
/**
* Remove a constraint from a table.
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
dropConstraint: (...args: Parameters<tables.DropConstraint>) => void;
/**
* Rename a constraint.
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
renameConstraint: (...args: Parameters<tables.RenameConstraint>) => void;
/**
* Add a constraint to a table.
*
* @alias addConstraint
*
* @see https://www.postgresql.org/docs/current/sql-altertable.html
*/
createConstraint: (...args: Parameters<tables.CreateConstraint>) => void;
/**
* Define a new data type.
*
* @alias addType
*
* @see https://www.postgresql.org/docs/current/sql-createtype.html
*/
createType: (...args: Parameters<types.CreateType>) => void;
/**
* Remove a data type.
*
* @see https://www.postgresql.org/docs/current/sql-droptype.html
*/
dropType: (...args: Parameters<types.DropType>) => void;
/**
* Define a new data type.
*
* @alias createType
*
* @see https://www.postgresql.org/docs/current/sql-createtype.html
*/
addType: (...args: Parameters<types.CreateType>) => void;
/**
* Rename a data type.
*
* @see https://www.postgresql.org/docs/current/sql-altertype.html
*/
renameType: (...args: Parameters<types.RenameType>) => void;
/**
* Rename a data type attribute.
*
* @see https://www.postgresql.org/docs/current/sql-altertype.html
*/
renameTypeAttribute: (...args: Parameters<types.RenameTypeAttribute>) => void;
/**
* Rename a data type value.
*
* @see https://www.postgresql.org/docs/current/sql-altertype.html
*/
renameTypeValue: (...args: Parameters<types.RenameTypeValue>) => void;
/**
* Add an attribute to a data type.
*
* @see https://www.postgresql.org/docs/current/sql-altertype.html
*/
addTypeAttribute: (...args: Parameters<types.AddTypeAttribute>) => void;
/**
* Remove an attribute from a data type.
*
* @see https://www.postgresql.org/docs/current/sql-altertype.html
*/
dropTypeAttribute: (...args: Parameters<types.DropTypeAttribute>) => void;
/**
* Set an attribute of a data type.
*
* @see https://www.postgresql.org/docs/current/sql-altertype.html
*/
setTypeAttribute: (...args: Parameters<types.SetTypeAttribute>) => void;
/**
* Add a value to a data type.
*
* @see https://www.postgresql.org/docs/current/sql-altertype.html
*/
addTypeValue: (...args: Parameters<types.AddTypeValue>) => void;
/**
* Define a new index.
*
* @alias addIndex
*
* @see https://www.postgresql.org/docs/current/sql-createindex.html
*/
createIndex: (...args: Parameters<indexes.CreateIndex>) => void;
/**
* Remove an index.
*
* @see https://www.postgresql.org/docs/current/sql-dropindex.html
*/
dropIndex: (...args: Parameters<indexes.DropIndex>) => void;
/**
* Define a new index.
*
* @alias createIndex
*
* @see https://www.postgresql.org/docs/current/sql-createindex.html
*/
addIndex: (...args: Parameters<indexes.CreateIndex>) => void;
/**
* Define a new database role.
*
* @see https://www.postgresql.org/docs/current/sql-createrole.html
*/
createRole: (...args: Parameters<roles.CreateRole>) => void;
/**
* Remove a database role.
*
* @see https://www.postgresql.org/docs/current/sql-droprole.html
*/
dropRole: (...args: Parameters<roles.DropRole>) => void;
/**
* Change a database role.
*
* @see https://www.postgresql.org/docs/current/sql-alterrole.html
*/
alterRole: (...args: Parameters<roles.AlterRole>) => void;
/**
* Rename a database role.
*
* @see https://www.postgresql.org/docs/current/sql-alterrole.html
*/
renameRole: (...args: Parameters<roles.RenameRole>) => void;
/**
* Define a new function.
*
* @see https://www.postgresql.org/docs/current/sql-createfunction.html
*/
createFunction: (...args: Parameters<functions.CreateFunction>) => void;
/**
* Remove a function.
*
* @see https://www.postgresql.org/docs/current/sql-dropfunction.html
*/
dropFunction: (...args: Parameters<functions.DropFunction>) => void;
/**
* Rename a function.
*
* @see https://www.postgresql.org/docs/current/sql-alterfunction.html
*/
renameFunction: (...args: Parameters<functions.RenameFunction>) => void;
/**
* Define a new trigger.
*
* @see https://www.postgresql.org/docs/current/sql-createtrigger.html
*/
createTrigger: (...args: Parameters<triggers.CreateTrigger>) => void;
/**
* Remove a trigger.
*
* @see https://www.postgresql.org/docs/current/sql-droptrigger.html
*/
dropTrigger: (...args: Parameters<triggers.DropTrigger>) => void;
/**
* Rename a trigger.
*
* @see https://www.postgresql.org/docs/current/sql-altertrigger.html
*/
renameTrigger: (...args: Parameters<triggers.RenameTrigger>) => void;
/**
* Define a new schema.
*
* @see https://www.postgresql.org/docs/current/sql-createschema.html
*/
createSchema: (...args: Parameters<schemas.CreateSchema>) => void;
/**
* Remove a schema.
*
* @see https://www.postgresql.org/docs/current/sql-dropschema.html
*/
dropSchema: (...args: Parameters<schemas.DropSchema>) => void;
/**
* Rename a schema.
*
* @see https://www.postgresql.org/docs/current/sql-alterschema.html
*/
renameSchema: (...args: Parameters<schemas.RenameSchema>) => void;
/**
* Define a new domain.
*
* @see https://www.postgresql.org/docs/current/sql-createdomain.html
*/
createDomain: (...args: Parameters<domains.CreateDomain>) => void;
/**
* Remove a domain.
*
* @see https://www.postgresql.org/docs/current/sql-dropdomain.html
*/
dropDomain: (...args: Parameters<domains.DropDomain>) => void;
/**
* Change the definition of a domain.
*
* @see https://www.postgresql.org/docs/current/sql-alterdomain.html
*/
alterDomain: (...args: Parameters<domains.AlterDomain>) => void;
/**
* Rename a domain.
*
* @see https://www.postgresql.org/docs/current/sql-alterdomain.html
*/
renameDomain: (...args: Parameters<domains.RenameDomain>) => void;
/**
* Define a new sequence generator.
*
* @see https://www.postgresql.org/docs/current/sql-createsequence.html
*/
createSequence: (...args: Parameters<sequences.CreateSequence>) => void;
/**
* Remove a sequence.
*
* @see https://www.postgresql.org/docs/current/sql-dropsequence.html
*/
dropSequence: (...args: Parameters<sequences.DropSequence>) => void;
/**
* Change the definition of a sequence generator.
*
* @see https://www.postgresql.org/docs/current/sql-altersequence.html
*/
alterSequence: (...args: Parameters<sequences.AlterSequence>) => void;
/**
* Rename a sequence.
*
* @see https://www.postgresql.org/docs/current/sql-altersequence.html
*/
renameSequence: (...args: Parameters<sequences.RenameSequence>) => void;
/**
* Define a new operator.
*
* @see https://www.postgresql.org/docs/current/sql-createoperator.html
*/
createOperator: (...args: Parameters<operators.CreateOperator>) => void;
/**
* Remove an operator.
*
* @see https://www.postgresql.org/docs/current/sql-dropoperator.html
*/
dropOperator: (...args: Parameters<operators.DropOperator>) => void;
/**
* Define a new operator class.
*
* @see https://www.postgresql.org/docs/current/sql-createopclass.html
*/
createOperatorClass: (...args: Parameters<operators.CreateOperatorClass>) => void;
/**
* Remove an operator class.
*
* @see https://www.postgresql.org/docs/current/sql-dropopclass.html
*/
dropOperatorClass: (...args: Parameters<operators.DropOperatorClass>) => void;
/**
* Rename an operator class.
*
* @see https://www.postgresql.org/docs/current/sql-alteropclass.html
*/
renameOperatorClass: (...args: Parameters<operators.RenameOperatorClass>) => void;
/**
* Define a new operator family.
*
* @see https://www.postgresql.org/docs/current/sql-createopfamily.html
*/
createOperatorFamily: (...args: Parameters<operators.CreateOperatorFamily>) => void;
/**
* Remove an operator family.
*
* @see https://www.postgresql.org/docs/current/sql-dropopfamily.html
*/
dropOperatorFamily: (...args: Parameters<operators.DropOperatorFamily>) => void;
/**
* Rename an operator family.
*
* @see https://www.postgresql.org/docs/current/sql-alteropfamily.html
*/
renameOperatorFamily: (...args: Parameters<operators.RenameOperatorFamily>) => void;
/**
* Add an operator to an operator family.
*
* @see https://www.postgresql.org/docs/current/sql-alteropfamily.html
*/
addToOperatorFamily: (...args: Parameters<operators.AddToOperatorFamily>) => void;
/**
* Remove an operator from an operator family.
*
* @see https://www.postgresql.org/docs/current/sql-alteropfamily.html
*/
removeFromOperatorFamily: (...args: Parameters<operators.RemoveFromOperatorFamily>) => void;
/**
* Define a new row-level security policy for a table.
*
* @see https://www.postgresql.org/docs/current/sql-createpolicy.html
*/
createPolicy: (...args: Parameters<policies.CreatePolicy>) => void;
/**
* Remove a row-level security policy from a table.
*
* @see https://www.postgresql.org/docs/current/sql-droppolicy.html
*/
dropPolicy: (...args: Parameters<policies.DropPolicy>) => void;
/**
* Change the definition of a row-level security policy.
*
* @see https://www.postgresql.org/docs/current/sql-alterpolicy.html
*/
alterPolicy: (...args: Parameters<policies.AlterPolicy>) => void;
/**
* Rename a row-level security policy.
*
* @see https://www.postgresql.org/docs/current/sql-alterpolicy.html
*/
renamePolicy: (...args: Parameters<policies.RenamePolicy>) => void;
/**
* Define a new view.
*
* @see https://www.postgresql.org/docs/current/sql-createview.html
*/
createView: (...args: Parameters<views.CreateView>) => void;
/**
* Remove a view.
*
* @see https://www.postgresql.org/docs/current/sql-dropview.html
*/
dropView: (...args: Parameters<views.DropView>) => void;
/**
* Change the definition of a view.
*
* @see https://www.postgresql.org/docs/current/sql-alterview.html
*/
alterView: (...args: Parameters<views.AlterView>) => void;
/**
* Change the definition of a view column.
*
* @see https://www.postgresql.org/docs/current/sql-alterview.html
*/
alterViewColumn: (...args: Parameters<views.AlterViewColumn>) => void;
/**
* Rename a view.
*
* @see https://www.postgresql.org/docs/current/sql-alterview.html
*/
renameView: (...args: Parameters<views.RenameView>) => void;
/**
* Define a new materialized view.
*
* @see https://www.postgresql.org/docs/current/sql-creatematerializedview.html
*/
createMaterializedView: (...args: Parameters<mViews.CreateMaterializedView>) => void;
/**
* Remove a materialized view.
*
* @see https://www.postgresql.org/docs/current/sql-dropmaterializedview.html
*/
dropMaterializedView: (...args: Parameters<mViews.DropMaterializedView>) => void;
/**
* Change the definition of a materialized view.
*
* @see https://www.postgresql.org/docs/current/sql-altermaterializedview.html
*/
alterMaterializedView: (...args: Parameters<mViews.AlterMaterializedView>) => void;
/**
* Rename a materialized view.
*
* @see https://www.postgresql.org/docs/current/sql-altermaterializedview.html
*/
renameMaterializedView: (...args: Parameters<mViews.RenameMaterializedView>) => void;
/**
* Rename a materialized view column.
*
* @see https://www.postgresql.org/docs/current/sql-altermaterializedview.html
*/
renameMaterializedViewColumn: (...args: Parameters<mViews.RenameMaterializedViewColumn>) => void;
/**
* Replace the contents of a materialized view.
*
* @see https://www.postgresql.org/docs/current/sql-refreshmaterializedview.html
*/
refreshMaterializedView: (...args: Parameters<mViews.RefreshMaterializedView>) => void;
/**
* Run raw SQL, with some optional _[very basic](http://mir.aculo.us/2011/03/09/little-helpers-a-tweet-sized-javascript-templating-engine/)_ mustache templating.
*
* This is a low-level operation, and you should use the higher-level operations whenever possible.
*
* @param sql SQL query to run.
* @param args Optional `key/val` of arguments to replace.
*
* @see https://www.postgresql.org/docs/current/sql-commands.html
*/
sql: (...args: Parameters<sql.Sql>) => void;
/**
* Inserts raw string, **which is not escaped**.
*
* @param sql String to **not escaped**.
*
* @example
* { default: pgm.func('CURRENT_TIMESTAMP') }
*/
func: (sql: string) => PgLiteral;
/**
* By default, all migrations are run in one transaction, but some DB
* operations like add type value (`pgm.addTypeValue`) does not work if the
* type is not created in the same transaction.
* e.g. if it is created in previous migration. You need to run specific
* migration outside a transaction (`pgm.noTransaction`).
* Be aware that this means that you can have some migrations applied and some
* not applied, if there is some error during migrating (leading to `ROLLBACK`).
*/
noTransaction: () => void;
/**
* The `db` client instance.
*
* Can be used to run queries directly.
*/
db: DB;

@@ -110,0 +546,0 @@ }

@@ -1,3 +0,4 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _decamelize = require('decamelize'); var _decamelize2 = _interopRequireDefault(_decamelize);
var _ = require('.');
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _decamelize = require('./decamelize');
var _identity = require('./identity');
var _quote = require('./quote');
function createSchemalize(options, _legacyShouldQuote) {

@@ -14,5 +15,5 @@ const { shouldDecamelize, shouldQuote } = typeof options === "boolean" ? {

const transform = [
shouldDecamelize ? _decamelize2.default : _.identity,
shouldQuote ? _.quote : _.identity
].reduce((acc, fn) => fn === _.identity ? acc : (str) => acc(fn(str)));
shouldDecamelize ? _decamelize.decamelize : _identity.identity,
shouldQuote ? _quote.quote : _identity.identity
].reduce((acc, fn) => fn === _identity.identity ? acc : (str) => acc(fn(str)));
return (value) => {

@@ -19,0 +20,0 @@ if (typeof value === "object") {

export { createSchemalize } from './createSchemalize';
export { createTransformer } from './createTransformer';
export { decamelize } from './decamelize';
export { escapeValue } from './escapeValue';

@@ -4,0 +5,0 @@ export { formatLines } from './formatLines';

"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _createSchemalize = require('./createSchemalize');
var _createTransformer = require('./createTransformer');
var _decamelize = require('./decamelize');
var _escapeValue = require('./escapeValue');

@@ -32,2 +33,3 @@ var _formatLines = require('./formatLines');

exports.PgLiteral = _PgLiteral.PgLiteral; exports.StringIdGenerator = _StringIdGenerator.StringIdGenerator; exports.applyType = _types.applyType; exports.applyTypeAdapters = _types.applyTypeAdapters; exports.createSchemalize = _createSchemalize.createSchemalize; exports.createTransformer = _createTransformer.createTransformer; exports.escapeValue = _escapeValue.escapeValue; exports.formatLines = _formatLines.formatLines; exports.formatParams = _formatParams.formatParams; exports.getMigrationTableSchema = _getMigrationTableSchema.getMigrationTableSchema; exports.getSchemas = _getSchemas.getSchemas; exports.identity = _identity.identity; exports.intersection = _intersection.intersection; exports.isPgLiteral = _PgLiteral.isPgLiteral; exports.makeComment = _makeComment.makeComment; exports.quote = _quote.quote;
exports.PgLiteral = _PgLiteral.PgLiteral; exports.StringIdGenerator = _StringIdGenerator.StringIdGenerator; exports.applyType = _types.applyType; exports.applyTypeAdapters = _types.applyTypeAdapters; exports.createSchemalize = _createSchemalize.createSchemalize; exports.createTransformer = _createTransformer.createTransformer; exports.decamelize = _decamelize.decamelize; exports.escapeValue = _escapeValue.escapeValue; exports.formatLines = _formatLines.formatLines; exports.formatParams = _formatParams.formatParams; exports.getMigrationTableSchema = _getMigrationTableSchema.getMigrationTableSchema; exports.getSchemas = _getSchemas.getSchemas; exports.identity = _identity.identity; exports.intersection = _intersection.intersection; exports.isPgLiteral = _PgLiteral.isPgLiteral; exports.makeComment = _makeComment.makeComment; exports.quote = _quote.quote;
{
"name": "node-pg-migrate",
"version": "7.0.0-alpha.3",
"version": "7.0.0-alpha.4",
"description": "Postgresql database migration management tool for node.js",

@@ -79,4 +79,2 @@ "bin": {

"dependencies": {
"decamelize": "^5.0.0",
"mkdirp": "~1.0.0",
"yargs": "~17.7.0"

@@ -88,10 +86,9 @@ },

"@types/config": "3.3.4",
"@types/mkdirp": "1.0.2",
"@types/node": "18.19.31",
"@types/pg": "8.11.5",
"@types/yargs": "17.0.32",
"@typescript-eslint/eslint-plugin": "7.6.0",
"@typescript-eslint/parser": "7.6.0",
"@vitest/coverage-v8": "1.4.0",
"@vitest/ui": "1.4.0",
"@typescript-eslint/eslint-plugin": "7.7.0",
"@typescript-eslint/parser": "7.7.0",
"@vitest/coverage-v8": "1.5.0",
"@vitest/ui": "1.5.0",
"config": "3.3.11",

@@ -116,3 +113,3 @@ "cross-env": "7.0.3",

"typescript": "4.8.4",
"vitest": "1.4.0"
"vitest": "1.5.0"
},

@@ -128,3 +125,2 @@ "peerDependencies": {

},
"packageManager": "pnpm@8.15.6",
"engines": {

@@ -131,0 +127,0 @@ "node": ">=16.18.0"

@@ -16,21 +16,26 @@ # node-pg-migrate

:warning: The project is currently in cleanup maintenance mode. So below sections are not up to date. :warning:
## Preconditions
### Looking for v3 docs?
- Node.js 18 or higher
- PostgreSQL 12.8 or higher (lower versions may work but are not supported officially)
see [v3 branch](https://github.com/salsita/node-pg-migrate/tree/v3).
If you don't already have the [`pg`](https://node-postgres.com/) library installed, you will need to add pg as either a direct or dev dependency
```bash
npm add pg
```
## Installation
$ npm install node-pg-migrate pg
```bash
npm add --save-dev node-pg-migrate
```
Installing this module adds a runnable file into your `node_modules/.bin` directory. If installed globally (with the -g option), you can run `node-pg-migrate` and if not, you can run `./node_modules/.bin/node-pg-migrate`
Installing this module adds a runnable file into your `node_modules/.bin` directory. If installed globally (with the -g option), you can run `node-pg-migrate` and if not, you can run `./node_modules/.bin/node-pg-migrate.js`
It will also install [`pg`](https://node-postgres.com/) library as it is peer dependency used for migrations.
## Quick Example
Add `"migrate": "node-pg-migrate"` to `scripts` section of `package.json` so you are able to quickly run commands.
Add `"migrate": "node-pg-migrate"` to `scripts` section of your `package.json` so you are able to quickly run commands.
Run `npm run migrate create my first migration`. It will create file `xxx_my-first-migration.js` in `migrations` folder.
Run `npm run migrate create my-first-migration`. It will create file `xxx_my-first-migration.js` in `migrations` folder.
Open it and change contents to:

@@ -75,5 +80,5 @@

If you will want to change your schema later, you can e.g. add lead paragraph to posts:
If you want to change your schema later, you can e.g. add lead paragraph to posts:
Run `npm run migrate create posts lead`, edit `xxx_posts_lead.js`:
Run `npm run migrate create posts_lead`, edit `xxx_posts_lead.js`:

@@ -88,3 +93,3 @@ ```js

Run `npm run migrate up` and there will be new column in `posts` table :tada: :tada:
Run `npm run migrate up` and there will be a new column in `posts` table :tada:

@@ -107,26 +112,2 @@ Want to know more? Read docs:

The MIT License (MIT)
Copyright (c) 2024 Christopher Quadflieg
Copyright (c) 2016-2021 Salsita Software &lt;jando@salsitasoft.com&gt;
Copyright (c) 2014-2016 Theo Ephraim
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
[MIT](./LICENSE)

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc