wipe views before foundation database code is executed
authorSteve Hackbarth <stephenhackbarth@gmail.com>
Thu, 4 Sep 2014 14:35:55 +0000 (10:35 -0400)
committerSteve Hackbarth <stephenhackbarth@gmail.com>
Thu, 4 Sep 2014 14:35:55 +0000 (10:35 -0400)
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 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"),