Merge pull request #1820 from shackbarth/wipe_early
authorTravis Webb <me@traviswebb.com>
Wed, 17 Sep 2014 15:52:32 +0000 (11:52 -0400)
committerTravis Webb <me@traviswebb.com>
Wed, 17 Sep 2014 15:52:32 +0000 (11:52 -0400)
wipe views before foundation database code is executed

.travis.yml
enyo-client/database/source/delete_system_orms.sql
enyo-client/database/source/wipe_views.sql [new file with mode: 0644]
scripts/lib/build_database.js
scripts/lib/util/process_manifest.js

index 10dcc2b..564ef54 100644 (file)
@@ -15,7 +15,3 @@ script:
   - "npm run-script test-datasource"
   - "npm run-script test"
   - "npm run-script jshint"
-
-  # test an upgrade from 4.4.0
-  - "wget http://sourceforge.net/projects/postbooks/files/03%20PostBooks-databases/4.4.0/postbooks_demo-4.4.0.backup"
-  - "./scripts/build_app.js -d upgrade_test -i -b ./postbooks_demo-4.4.0.backup"
index dc1cfbc..79e2b31 100644 (file)
@@ -2,19 +2,6 @@ DO $$
  /* Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
      See www.xm.ple.com/CPAL for the full text of the software license. */
 
-  var result,
-    viewname,
-    schemaname,
-    i;
-
-  sql = "select schemaname, viewname from pg_views where schemaname in ('xm','sys', 'xt');"
-  result = plv8.execute(sql);
-  for (i = 0; i < result.length; i++) {
-    viewname = result[i].viewname;
-    schemaname = result[i].schemaname;
-    plv8.execute('drop view if exists ' + schemaname + '.' + viewname + ' cascade;');
-  }
-
   plv8.execute("select xt.js_init()");
   plv8.execute("alter table xt.orm disable trigger orm_did_change");
   plv8.execute("delete from xt.orm where orm_json ~ '\"isSystem\":true';");
diff --git a/enyo-client/database/source/wipe_views.sql b/enyo-client/database/source/wipe_views.sql
new file mode 100644 (file)
index 0000000..87ec0d3
--- /dev/null
@@ -0,0 +1,19 @@
+DO $$
+ /* Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.
+     See www.xm.ple.com/CPAL for the full text of the software license. */
+
+  var sql,
+    result,
+    viewname,
+    schemaname,
+    i;
+
+  sql = "select schemaname, viewname from pg_views where schemaname in ('xm','sys', 'xt');"
+  result = plv8.execute(sql);
+  for (i = 0; i < result.length; i++) {
+    viewname = result[i].viewname;
+    schemaname = result[i].schemaname;
+    plv8.execute('drop view if exists ' + schemaname + '.' + viewname + ' cascade;');
+  }
+
+$$ language plv8;
index 6f64695..aa0b85c 100644 (file)
@@ -89,7 +89,8 @@ var  async = require('async'),
               baseName.indexOf('distribution') >= 0,
             registerExtension: isExtension,
             runJsInit: !isFoundation && !isLibOrm,
-            wipeViews: isApplicationCore && spec.wipeViews,
+            wipeViews: isFoundation && spec.wipeViews,
+            wipeOrms: isApplicationCore && spec.wipeViews,
             extensionLocation: isCoreExtension ? "/core-extensions" :
               isPublicExtension ? "/xtuple-extensions" :
               isPrivateExtension ? "/private-extensions" :
index 90f6030..44ed46a 100644 (file)
@@ -56,6 +56,19 @@ regexp:true, undef:true, strict:true, trailing:true, white:true */
     }
 
     if (options.wipeViews) {
+      // If we want to pre-emptively wipe out the views, the best place to do it
+      // is at the start of the core application code
+      fs.readFile(path.join(__dirname, "../../../enyo-client/database/source/wipe_views.sql"),
+          function (err, wipeSql) {
+        if (err) {
+          callback(err);
+          return;
+        }
+        extensionSql = wipeSql + extensionSql;
+        callback(null, extensionSql);
+      });
+
+    } else if (options.wipeOrms) {
       // If we want to pre-emptively wipe out the views, the best place to do it
       // is at the start of the core application code
       fs.readFile(path.join(__dirname, "../../../enyo-client/database/source/delete_system_orms.sql"),