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

flexgres

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flexgres - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

128

flexgres.js

@@ -25,20 +25,24 @@ /* Getting Started

function(callback) {
var q =
`
SELECT * FROM information_schema.columns
WHERE table_name = 'test'
`;
async.eachSeries(config.tables, function(table,callbackEach) {
var q =
`
SELECT * FROM information_schema.columns
WHERE table_name = '`+ table.tableName +`'
`;
if (logging == true) console.log(q);
if (logging == true) console.log(q);
client.query(q, function(err, result) {
if (err) throw err;
result.rows.map(function(row) {
diffs.push({
"table": row.table_name,
"column": row.column_name,
"null": row.is_nullable,
"dtype": row.data_type
client.query(q, function(err, result) {
if (err) throw err
result.rows.map(function(row) {
diffs.push({
"table": row.table_name,
"column": row.column_name,
"null": row.is_nullable,
"dtype": row.data_type
})
})
callbackEach();
})
}, function() {
callback();

@@ -50,15 +54,15 @@ })

async.eachSeries(tables, function(table, callbackEach) {
var t = tables.filter(function(t) {
var c = table.columns;
var t = c.filter(function(t) {
var truthy = true;
diffs.map(function(diff) {
if (t.tableName == diffs.table) {
return true;
if (t.name.toUpperCase() == diff.column.toUpperCase()) {
truthy = false;
}
})
return false;
return truthy;
});
if (t.length > 0) {
var c = t[0].columns.filter(function(co) {
co.column == diff.column
});
c = t[0];
} else {

@@ -68,16 +72,18 @@ return callbackEach();

if (c.length == 0) {
d = c.type;
c = c.null;
console.log(c);
var d = diff.dtype.toUpperCase();
q =
`
ALTER TABLE `+diff.table+` ADD `+diff.column+`
`+d+` `+n+`
`
var d = c.type.toUpperCase();
var n = c.null;
if (n == false) {
n = "NOT NULL";
} else {
return callbackEach();
n = "";
}
q =
`
ALTER TABLE `+table.tableName+` ADD `+c.name+`
`+d+` `+n+`
`
if (logging == true) console.log(q);

@@ -97,5 +103,6 @@

var structure = "";
var q1, q2, flag = false;
var t = tables.filter(function(t) {
return t.tableName == diff.table
return t.tableName.toUpperCase() == diff.table.toUpperCase()
});

@@ -108,15 +115,22 @@

var c = t[0].columns.filter(function(co) {
return co.name == diff.column;
})[0];
return co.name.toUpperCase() == diff.column.toUpperCase();
});
if (c.length == 0) {
q =
q1 =
`
ALTER TABLE `+diff.table+` DROP COLUMN `+diff.column+`
`
if (logging == true) console.log("s1", q1);
flag = true;
client.query(q1, function(err, result) {
if (err) throw err;
})
} else if (c.length == 1 && diff) {
var dt = diff.dtype.toUpperCase();
var ct = c.type.toUpperCase();
var ct = c[0].type.toUpperCase();
var nt = ct;
ct = ct

@@ -141,4 +155,3 @@ .replace("INT", "INTEGER")

if (
(diff.null == "NO" && c.null == false) &&
dt == ct
diff.null == "NO" && c[0].null == false && dt == ct
) {

@@ -154,21 +167,37 @@ return callbackEach();

var d = diff.dtype.toUpperCase();
var d = nt;
q =
q1 =
`
ALTER TABLE `+diff.table+` MODIFY `+diff.column+`
`+d+` `+n+`
ALTER TABLE `+diff.table+` DROP `+diff.column+`
`
q2 =
`
ALTER TABLE `+diff.table+` ADD `+diff.column+` `+d+` `+n+`
`
} else {
callbackEach();
return callbackEach();
}
if (logging == true) console.log(q);
async.series([
function(callback2) {
if (flag == true) return callbackEach();
if (logging == true) console.log("s2", q1);
client.query(q1, function(err, result) {
if (err) throw err;
return callback2();
})
},
function(callback2) {
if (logging == true) console.log(q2);
client.query(q2, function(err, result) {
if (err) throw err;
return callbackEach();
})
}
])
client.query(q, function(err, result) {
if (err) throw err;
callbackEach();
})
}, function() {
callback();
return callback();
})

@@ -190,3 +219,2 @@ },

result.rows.map(function(t) {
console.log(t);
diffsTbl.push(t.table_name);

@@ -193,0 +221,0 @@ })

{
"name": "flexgres",
"version": "0.1.2",
"version": "0.2.0",
"description": "Flexibly change your Postgres schemas with Flexgres.",

@@ -5,0 +5,0 @@ "main": "flexgres.js",

@@ -25,3 +25,3 @@ # flexgres

var client = require("pg");
var pg = require("pg");
var queryConn = "postgres://"+name+":"+password+"@"+host+":"+port+"/"+db+"";

@@ -28,0 +28,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