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

@vbilopav/pgmigrations

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vbilopav/pgmigrations - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

pgmigrations.js

8

config.js

@@ -17,2 +17,10 @@ const crypto = require('crypto');

migrationDir: "",
upDirs: [],
downDirs: [],
repetableDirs: [],
repetableBeforeDirs: [],
beforeDirs: [],
afterDirs: [],
keepMigrationDirHistory: false,

@@ -19,0 +27,0 @@ upPrefix: "V",

84

migration.js

@@ -74,3 +74,3 @@ const path = require("path");

var mandatory = [
"migrationDir","upPrefix","downPrefix","repetablePrefix","repetableBeforePrefix",
"upPrefix","downPrefix","repetablePrefix","repetableBeforePrefix",
"beforePrefix","afterPrefix","separatorPrefix",

@@ -114,7 +114,2 @@ "historyTableName","historyTableSchema",

{
if (!fs.existsSync(config.migrationDir) || !fs.lstatSync(config.migrationDir).isDirectory()) {
error(`Migration directory ${config.migrationDir} does not exist or is not a directory. Please provide a valid migration directory.`);
return;
}
if (!fs.existsSync(config.tmpDir)) {

@@ -168,4 +163,38 @@ if (opt.verbose) {

const hasMultipleDirs = Array.isArray(config.migrationDir) || config.upDirs.length || config.downDirs.length || config.repetableDirs.length || config.repetableBeforeDirs.length || config.beforeDirs.length || config.afterDirs.length;
const migrationDirs = Array.isArray(config.migrationDir) ? config.migrationDir : [config.migrationDir];
const upDirsHash = {};
const downDirsHash = {};
const repetableDirsHash = {};
const repetableBeforeDirsHash = {};
const beforeDirsHash = {};
const afterDirsHash = {};
if (config.upDirs && config.upDirs.length > 0) {
migrationDirs.push(...config.upDirs);
config.upDirs.forEach(d => upDirsHash[d] = true);
}
if (config.downDirs && config.downDirs.length > 0) {
migrationDirs.push(...config.downDirs);
config.downDirs.forEach(d => downDirsHash[d] = true);
}
if (config.repetableDirs && config.repetableDirs.length > 0) {
migrationDirs.push(...config.repetableDirs);
config.repetableDirs.forEach(d => repetableDirsHash[d] = true);
}
if (config.repetableBeforeDirs && config.repetableBeforeDirs.length > 0) {
migrationDirs.push(...config.repetableBeforeDirs);
config.repetableBeforeDirs.forEach(d => repetableBeforeDirsHash[d] = true);
}
if (config.beforeDirs && config.beforeDirs.length > 0) {
migrationDirs.push(...config.beforeDirs);
config.beforeDirs.forEach(d => beforeDirsHash[d] = true);
}
if (config.afterDirs && config.afterDirs.length > 0) {
migrationDirs.push(...config.afterDirs);
config.afterDirs.forEach(d => afterDirsHash[d] = true);
}
const beforeList = [];

@@ -189,2 +218,5 @@ const repetableBeforeList = [];

const migrationDir = migrationDirs[i];
if (!migrationDir) {
continue;
}
if (!fs.existsSync(migrationDir) || !fs.lstatSync(migrationDir).isDirectory()) {

@@ -205,3 +237,9 @@ error(`Migration directory ${migrationDir} does not exist or is not a directory. Please provide a valid migration directory.`);

if (fileName.indexOf(config.separatorPrefix) == -1) {
if (fileName.indexOf(config.separatorPrefix) == -1
&& repetableDirsHash[migrationDir] == false
&& repetableBeforeDirsHash[migrationDir] == false
&& beforeDirsHash[migrationDir] == false
&& afterDirsHash[migrationDir] == false
&& upDirsHash[migrationDir] == false
&& downDirsHash[migrationDir] == false) {
warning(`Migration file ${fileName} does not contain separator prefix ${config.separatorPrefix}. Skipping...`);

@@ -214,6 +252,7 @@ return;

let suffix = parts.slice(1).join(config.separatorPrefix);
let name = Array.isArray(config.migrationDir) ?
migrationDir.split(".").slice(0, -1).join(".").replace(/_/g, " ") + " " + suffix.split(".").slice(0, -1).join(".").replace(/_/g, " ") :
let name = hasMultipleDirs ?
(migrationDir.replace(/_/g, " ").replace(/\./g, " ") + " " + suffix.split(".").slice(0, -1).join(".").replace(/_/g, " ")).trim() :
suffix.split(".").slice(0, -1).join(".").replace(/_/g, " ");
let version = null;

@@ -225,7 +264,7 @@ let type = null;

const hash = config.hashFunction(content);
const script = Array.isArray(config.migrationDir) ? migrationDir + "/" + fileName : fileName;
const script = hasMultipleDirs ? migrationDir + "/" + fileName : fileName;
let pushTo = null;
if (prefix.startsWith(config.upPrefix)) {
if (prefix.startsWith(config.upPrefix) || upDirsHash[migrationDir]) {
if (isUp) {

@@ -240,2 +279,7 @@ version = prefix.slice(config.upPrefix.length).trim();

if (!version) {
warning(`Migration file ${migrationDir}/${fileName} does not contain version. Skipping...`);
return;
}
if (versionDict[version]) {

@@ -255,3 +299,3 @@ return;

} else if (prefix.startsWith(config.downPrefix)) {
} else if (prefix.startsWith(config.downPrefix) || downDirsHash[migrationDir]) {
if (isDown) {

@@ -266,2 +310,7 @@ version = prefix.slice(config.downPrefix.length).trim();

if (!version) {
warning(`Migration file ${migrationDir}/${fileName} does not contain version. Skipping...`);
return;
}
if (!versionDict[version]) {

@@ -281,3 +330,4 @@ return;

}
} else if (prefix == config.repetablePrefix) {
} else if (prefix == config.repetablePrefix || repetableDirsHash[migrationDir]) {
if (isUp) {

@@ -291,3 +341,3 @@ type = types.repetable;

}
} else if (prefix == config.repetableBeforePrefix) {
} else if (prefix == config.repetableBeforePrefix || repetableBeforeDirsHash[migrationDir]) {
if (isUp) {

@@ -300,3 +350,3 @@ type = types.repetableBefore;

}
} else if (prefix == config.beforePrefix) {
} else if (prefix == config.beforePrefix || beforeDirsHash[migrationDir]) {
if (isUp) {

@@ -307,3 +357,3 @@ type = types.before;

} else if (prefix == config.afterPrefix) {
} else if (prefix == config.afterPrefix || afterDirsHash[migrationDir]) {
if (isUp) {

@@ -310,0 +360,0 @@ type = types.after;

{
"name": "@vbilopav/pgmigrations",
"version": "0.0.6",
"version": "0.0.7",
"description": "PostgreSQL Migration Tool for Node.js and NPM",

@@ -8,3 +8,3 @@ "author": "vb-consulting",

"bin": {
"pgmigrations": "./db.js"
"pgmigrations": "./pgmigrations.js"
},

@@ -11,0 +11,0 @@ "repository": {

@@ -167,3 +167,3 @@ # PgMigrations

The tool will try to read the default configuration file from the running location. The default configuration file is `pg.js` or it can be set with a command line switch `--config=[file]`.
The tool will try to read the default configuration file from the running location. The default configuration file is `db.js` or it can be set with a command line switch `--config=[file]`.

@@ -247,4 +247,28 @@ Example:

The default value is not set (empty string). This value needs to be set for every migration project (mandatory).
The default value is not set (empty string). This value needs to be set for every migration project.
#### upDirs
List of directories for versioned UP migrations. Prefix and version number is mandatory.
#### downDirs
List of directories for versioned DOWN migrations. Prefix and version number is mandatory.
#### repetableDirs
List of directories for versioned REPETABLE migrations. Prefix and version number is mandatory.
#### repetableBeforeDirs
List of directories for versioned REPETABLE BEFORE migrations. Prefix and version number is mandatory.
#### beforeDirs
List of directories for versioned BEFORE migrations. Prefix and version number is mandatory.
#### afterDirs
List of directories for versioned AFTER migrations. Prefix and version number is mandatory.
#### keepMigrationDirHistory

@@ -251,0 +275,0 @@

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