create_schema function
authorSteve Hackbarth <stephenhackbarth@gmail.com>
Tue, 19 Aug 2014 04:33:33 +0000 (23:33 -0500)
committerSteve Hackbarth <stephenhackbarth@gmail.com>
Tue, 19 Aug 2014 04:33:33 +0000 (23:33 -0500)
lib/orm/source/create_sys_schema.sql
lib/orm/source/create_xm_schema.sql
lib/orm/source/manifest.js
lib/orm/source/xt/functions/create_schema.sql [new file with mode: 0644]

index 2d71da0..419d819 100644 (file)
@@ -1,9 +1 @@
-do $$
-  /* Only create the schema if it hasn't been created already */
-  var res, sql = "select schema_name from information_schema.schemata where schema_name = 'sys'",
-  res = plv8.execute(sql);
-  if (!res.length) {
-    sql = "create schema sys; grant all on schema sys to group xtrole;"
-    plv8.execute(sql);
-  }
-$$ language plv8;
+select xt.create_schema('sys');
index 4f21c27..933c25a 100644 (file)
@@ -1,9 +1 @@
-do $$
-  /* Only create the schema if it hasn't been created already */
-  var res, sql = "select schema_name from information_schema.schemata where schema_name = 'xm'",
-  res = plv8.execute(sql);
-  if (!res.length) {
-    sql = "create schema xm; grant all on schema xm to group xtrole;"
-    plv8.execute(sql);
-  }
-$$ language plv8;
\ No newline at end of file
+select xt.create_schema('xm');
index 025466b..e8ef2d1 100644 (file)
@@ -3,8 +3,6 @@
   "version": "1.3.9",
   "databaseScripts": [
     "create_plv8.sql",
-    "create_xm_schema.sql",
-    "create_sys_schema.sql",
     "xt/functions/add_inheritance.sql",
     "xt/functions/any_numeric.sql",
     "xt/functions/any_text.sql",
@@ -24,6 +22,9 @@
     "xt/functions/js_init.sql",
     "xt/functions/install_js.sql",
     "xt/functions/install_orm.sql",
+    "xt/functions/create_schema.sql",
+    "create_sys_schema.sql",
+    "create_xm_schema.sql",
     "xt/functions/is_date.sql",
     "xt/functions/not_any_numeric.sql",
     "xt/functions/not_any_text.sql",
diff --git a/lib/orm/source/xt/functions/create_schema.sql b/lib/orm/source/xt/functions/create_schema.sql
new file mode 100644 (file)
index 0000000..586a69b
--- /dev/null
@@ -0,0 +1,9 @@
+create or replace function xt.create_schema(schema_name text) returns boolean volatile as $$
+  /* Only create the schema if it hasn't been created already */
+  var res, sql = "select schema_name from information_schema.schemata where schema_name = $1",
+  res = plv8.execute(sql, [schema_name]);
+  if (!res.length) {
+    sql = "create schema %1$I; grant all on schema %1$I to group xtrole;"
+    plv8.execute(XT.format(sql, [schema_name]));
+  }
+$$ language plv8;