issue #23982: correctly prepopulate some credit card data
authorSteve Hackbarth <stephenhackbarth@gmail.com>
Tue, 24 Jun 2014 03:47:29 +0000 (23:47 -0400)
committerSteve Hackbarth <stephenhackbarth@gmail.com>
Tue, 24 Jun 2014 03:47:29 +0000 (23:47 -0400)
enyo-client/database/source/populate_data.js [new file with mode: 0644]
scripts/build_app.js
scripts/lib/build_all.js
scripts/lib/build_database.js
test/build/build_app.js

diff --git a/enyo-client/database/source/populate_data.js b/enyo-client/database/source/populate_data.js
new file mode 100644 (file)
index 0000000..1cd4cfa
--- /dev/null
@@ -0,0 +1,3 @@
+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"}
+];
index 72b9bb8..f15d6ef 100755 (executable)
@@ -23,6 +23,7 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
     .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.')
@@ -38,6 +39,7 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
     frozen: program.frozen,
     initialize: program.initialize,
     keepSql: program.keepsql,
+    populateData: program.populate,
     source: program.source,
     unregister: program.unregister,
     wipeViews: !program.quick && !program.extension,
index 4ddeca2..36c9303 100644 (file)
@@ -82,6 +82,7 @@ var _ = require('underscore'),
               extensions: _.compact(paths),
               database: database,
               keepSql: options.keepSql,
+              populateData: options.populateData,
               wipeViews: options.wipeViews,
               clientOnly: options.clientOnly,
               databaseOnly: options.databaseOnly
@@ -141,6 +142,7 @@ var _ = require('underscore'),
       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
 
@@ -182,6 +184,7 @@ var _ = require('underscore'),
       }
       buildSpecs.initialize = true;
       buildSpecs.keepSql = options.keepSql;
+      buildSpecs.populateData = options.populateData;
       buildSpecs.wipeViews = options.wipeViews;
       buildSpecs.clientOnly = options.clientOnly;
       buildSpecs.databaseOnly = options.databaseOnly;
@@ -217,6 +220,7 @@ var _ = require('underscore'),
           database: database,
           frozen: options.frozen,
           keepSql: options.keepSql,
+          populateData: options.populateData,
           wipeViews: options.wipeViews,
           clientOnly: options.clientOnly,
           databaseOnly: options.databaseOnly,
index f7f8934..de656f5 100644 (file)
@@ -221,7 +221,20 @@ var  async = require('async'),
         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);
+          }
         });
       });
     };
index f9ba4ed..687f844 100644 (file)
@@ -23,6 +23,7 @@ var buildAll = require('../../scripts/lib/build_all'),
       buildAll.build({
         database: databaseName,
         initialize: true,
+        populateData: true,
         source: path.join(__dirname, "../../foundation-database/postbooks_demo_data.sql")
       }, function (err, res) {
         assert.isNull(err);