"version": "1.3.9",
"databaseScripts": [
"create_plv8.sql",
+ "xt/functions/create_schema.sql",
+ "create_sys_schema.sql",
+ "create_xm_schema.sql",
"xt/functions/add_inheritance.sql",
"xt/functions/any_numeric.sql",
"xt/functions/any_text.sql",
"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",
-create or replace function xt.create_schema(schema_name text) returns boolean volatile as $$
+create or replace function xt.create_schema(sch text) returns boolean volatile as $$
+declare
+ count integer;
+ query text;
+begin
+
/* 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;
+ perform *
+ from information_schema.schemata
+ where schema_name = sch;
+
+ get diagnostics count = row_count;
+
+ if (count > 0) then
+ return false;
+ end if;
+
+ query = 'create schema ' || sch || ';' ||
+ 'grant all on schema ' || sch || ' to group xtrole;';
+ execute query;
+
+ return true;
+
+end;
+$$ language 'plpgsql';