-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');
-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');
"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",
"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",
--- /dev/null
+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;