--- /dev/null
+exports.commands = [
+ {"nameSpace":"XM","type":"Customer","id":"TTOYS","lock":{"effective":"2014-06-24T00:20:04.951Z","key":9,"username":"admin"},"patches":[{"op":"add","path":"/creditCards/0","value":{"isActive":true,"name":"John Brown","address1":"123 Test St","address2":"","city":"Norfolk","country":"United States","state":"VA","zip":"23517","creditCardType":"V","number":"4111111111111111","monthExpired":"12","yearExpired":"2020"}}],"binaryField":null,"requery":false,"encoding":"rjson","username":"admin","encryptionKey":"this is any content"}
+];
.option('-f, --frozen', 'Apply frozen scripts for first-time foundation extension installs.')
.option('-i, --initialize', 'Initialize database. Must be used with the -b or -s flag.')
.option('-k, --keepsql', 'Do not delete the temporary sql files that represent the payload of the build.')
+ .option('-p, --populate', 'Populate data.')
.option('-q, --quick', 'Quicken install by not dropping the views pre-emptively.')
.option('-s, --source [/path/to/source_data.sql]', 'Location of source data. Must be used with the -i flag.')
.option('-u, --unregister', 'Unregister an extension.')
frozen: program.frozen,
initialize: program.initialize,
keepSql: program.keepsql,
+ populateData: program.populate,
source: program.source,
unregister: program.unregister,
wipeViews: !program.quick && !program.extension,
extensions: _.compact(paths),
database: database,
keepSql: options.keepSql,
+ populateData: options.populateData,
wipeViews: options.wipeViews,
clientOnly: options.clientOnly,
databaseOnly: options.databaseOnly
config = require(path.join(__dirname, "../../node-datasource/config.js"));
}
creds = config.databaseServer;
+ creds.encryptionKeyFile = config.datasource.encryptionKeyFile;
creds.host = creds.hostname; // adapt our lingo to node-postgres lingo
creds.username = creds.user; // adapt our lingo to orm installer lingo
}
buildSpecs.initialize = true;
buildSpecs.keepSql = options.keepSql;
+ buildSpecs.populateData = options.populateData;
buildSpecs.wipeViews = options.wipeViews;
buildSpecs.clientOnly = options.clientOnly;
buildSpecs.databaseOnly = options.databaseOnly;
database: database,
frozen: options.frozen,
keepSql: options.keepSql,
+ populateData: options.populateData,
wipeViews: options.wipeViews,
clientOnly: options.clientOnly,
databaseOnly: options.databaseOnly,
winston.info("Applying build to database " + spec.database);
credsClone.database = spec.database;
buildDatabaseUtil.sendToDatabase(allSql, credsClone, spec, function (err, res) {
- databaseCallback(err, res);
+ if (spec.populateData) {
+ var commands = require(path.join(__dirname, "../../enyo-client/database/source/populate_data")).commands;
+ var populateSql = "DO $$ XT.disableLocks = true; $$ language plv8;";
+ var encryptionKey = fs.readFileSync(path.join(__dirname, "../../node-datasource", creds.encryptionKeyFile), "utf8");
+ _.each(commands, function (command) {
+ command.encryptionKey = encryptionKey;
+ command.username = creds.username;
+ populateSql += "select xt.patch(\'" + JSON.stringify(command) + "\');";
+ });
+ populateSql += "DO $$ XT.disableLocks = undefined; $$ language plv8;";
+ dataSource.query(populateSql, credsClone, databaseCallback);
+ } else {
+ databaseCallback(err, res);
+ }
});
});
};
buildAll.build({
database: databaseName,
initialize: true,
+ populateData: true,
source: path.join(__dirname, "../../foundation-database/postbooks_demo_data.sql")
}, function (err, res) {
assert.isNull(err);