From: Steve Hackbarth Date: Fri, 19 Sep 2014 14:18:01 +0000 (-0400) Subject: Merge remote-tracking branch 'XTUPLE/4_7_x' into 1855 X-Git-Tag: v4.7.0-beta.2~8^2~1 X-Git-Url: http://git.roojs.org/?a=commitdiff_plain;h=92846f11993934f7e77c339beb3bb7d50d4a7384;hp=b5e70f88ae2d22f9c98b78ab258990a74af67fec;p=xtuple Merge remote-tracking branch 'XTUPLE/4_7_x' into 1855 --- diff --git a/enyo-client/database/source/delete_system_orms.sql b/enyo-client/database/source/delete_system_orms.sql index 79e2b31e9..66ea97675 100644 --- a/enyo-client/database/source/delete_system_orms.sql +++ b/enyo-client/database/source/delete_system_orms.sql @@ -1,10 +1,10 @@ -DO $$ +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. */ + See www.xtuple.com/CPAL for the full text of the software license. */ - plv8.execute("select xt.js_init()"); - plv8.execute("alter table xt.orm disable trigger orm_did_change"); + 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';"); - plv8.execute("alter table xt.orm enable trigger orm_did_change"); + plv8.execute("alter table xt.orm enable trigger orm_did_change;"); $$ language plv8; diff --git a/enyo-client/database/source/wipe_views.sql b/enyo-client/database/source/wipe_views.sql index 87ec0d33f..b92157597 100644 --- a/enyo-client/database/source/wipe_views.sql +++ b/enyo-client/database/source/wipe_views.sql @@ -1,19 +1,16 @@ -DO $$ +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; +declare + sqlstring text; +begin + select string_agg('drop view ' || t.oid::regclass || ';', ' ') into sqlstring + from pg_class t + join pg_namespace n on n.oid = relnamespace + where relkind = 'v' + and nspname in ('xm','sys', 'xt'); + if length(sqlstring) > 0 then + execute sqlstring; + end if; +end +$$; diff --git a/enyo-client/database/source/xt/functions/pg_advisory_unlock.sql b/enyo-client/database/source/xt/functions/pg_advisory_unlock.sql index c892882ca..25c3b7aff 100644 --- a/enyo-client/database/source/xt/functions/pg_advisory_unlock.sql +++ b/enyo-client/database/source/xt/functions/pg_advisory_unlock.sql @@ -1,4 +1,8 @@ create or replace function xt.pg_advisory_unlock(oid integer, id integer) returns boolean as $$ + var sql = "select pg_catalog.pg_advisory_unlock($1, $2) as result;"; + return plv8.execute(sql, [oid, id])[0].result; + /* temporary: let qt client use advisory locks but web client use xt.lock */ + var pid = plv8.execute("select pg_backend_pid() as pid;")[0].pid, username = plv8.execute("select geteffectivextuser() as username;")[0].username, sql = "select * from xt.lock where lock_table_oid = $1 and lock_record_id = $2 and lock_username = $3 and lock_pid = $4;", diff --git a/enyo-client/database/source/xt/functions/trylock.sql b/enyo-client/database/source/xt/functions/trylock.sql index 0c73312f6..719607b4d 100644 --- a/enyo-client/database/source/xt/functions/trylock.sql +++ b/enyo-client/database/source/xt/functions/trylock.sql @@ -1,4 +1,8 @@ create or replace function xt.trylock(oid integer, id integer) returns boolean as $$ + var sql = "select public.trylock($1, $2) as result;"; + return plv8.execute(sql, [oid, id])[0].result; + /* temporary: let qt client use advisory locks but web client use xt.lock */ + var pid = plv8.execute("select pg_backend_pid() as pid;")[0].pid, data = Object.create(XT.Data), lock = data.tryLock(oid, id, {pid: pid}); diff --git a/enyo-client/extensions/source/sales/database/source/manifest.js b/enyo-client/extensions/source/sales/database/source/manifest.js index ce8ba7741..a0938aaf7 100644 --- a/enyo-client/extensions/source/sales/database/source/manifest.js +++ b/enyo-client/extensions/source/sales/database/source/manifest.js @@ -10,6 +10,7 @@ "xt/views/share_users_shipto.sql", "xt/views/share_users_shipto_cntct.sql", "xt/views/share_users_shipto_addr.sql", + "xt/views/share_users_shipto_cust.sql", "xt/tables/sharetype.sql" ] } diff --git a/enyo-client/extensions/source/sales/database/source/xt/tables/sharetype.sql b/enyo-client/extensions/source/sales/database/source/xt/tables/sharetype.sql index 69301f323..3e343bf4c 100644 --- a/enyo-client/extensions/source/sales/database/source/xt/tables/sharetype.sql +++ b/enyo-client/extensions/source/sales/database/source/xt/tables/sharetype.sql @@ -54,6 +54,20 @@ insert into xt.sharetype ( 'username' ); +-- Customer that a Ship To is on CRM Account's users. +delete from xt.sharetype where sharetype_tblname = 'share_users_shipto_cust'; +insert into xt.sharetype ( + sharetype_nsname, + sharetype_tblname, + sharetype_col_obj_uuid, + sharetype_col_username +) values ( + 'xt', + 'share_users_shipto_cust', + 'obj_uuid', + 'username' +); + -- Sales Order CRM Account's users. delete from xt.sharetype where sharetype_tblname = 'share_users_cohead'; insert into xt.sharetype ( diff --git a/enyo-client/extensions/source/sales/database/source/xt/views/share_users_shipto_cust.sql b/enyo-client/extensions/source/sales/database/source/xt/views/share_users_shipto_cust.sql new file mode 100644 index 000000000..d852f1fbc --- /dev/null +++ b/enyo-client/extensions/source/sales/database/source/xt/views/share_users_shipto_cust.sql @@ -0,0 +1,31 @@ +/* + * This view lists all postgres usernames that are associated with a CRM + * Account that owns a resource. That associaiton is either the main user + * account, owner's user account, customer's sale rep's user account or + * a shared access that has been specifically granted. + * + * This view can be used to determine which users have personal privilege + * access to a Customer that a Ship To is on based on what CRM Account the + * Ship To belongs to. + */ + +select xt.create_view('xt.share_users_shipto_cust', $$ + + -- Customer that is for a Ship To CRM Account's users. + SELECT + shipto_cust_crmacct_id.obj_uuid::uuid AS obj_uuid, + username::text AS username + FROM ( + SELECT + custinfo.obj_uuid, + crmacct.crmacct_id + FROM shiptoinfo + LEFT JOIN crmacct ON crmacct_cust_id = shipto_cust_id + LEFT JOIN custinfo ON cust_id = shipto_cust_id + ) shipto_cust_crmacct_id + LEFT JOIN xt.crmacct_users USING (crmacct_id) + WHERE 1=1 + AND username IS NOT NULL + AND obj_uuid IS NOT NULL; + +$$, false); diff --git a/foundation-database/public/functions/logout.sql b/foundation-database/public/functions/logout.sql index 1626bf200..5806fc812 100644 --- a/foundation-database/public/functions/logout.sql +++ b/foundation-database/public/functions/logout.sql @@ -3,9 +3,16 @@ CREATE OR REPLACE FUNCTION logout() RETURNS integer AS $$ -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. -- See www.xtuple.com/CPAL for the full text of the software license. BEGIN - PERFORM pg_advisory_unlock(datid::integer, procpid) + IF (compareversion('9.2.0') <= 0) + THEN + PERFORM pg_advisory_unlock(datid::integer, pid) FROM pg_stat_activity - WHERE(procpid = pg_backend_pid()); + WHERE(pid = pg_backend_pid()); + ELSE + PERFORM pg_advisory_unlock(datid::integer, procpid) + FROM pg_stat_activity + WHERE(procpid = pg_backend_pid()); + END IF; RETURN 0; END; diff --git a/lib/orm/source/xt/javascript/data.sql b/lib/orm/source/xt/javascript/data.sql index 0cacd1851..ada5e1bdf 100644 --- a/lib/orm/source/xt/javascript/data.sql +++ b/lib/orm/source/xt/javascript/data.sql @@ -1727,6 +1727,31 @@ select xt.install_js('XT','Data','xtuple', $$ return ret; }, + /** + * Get the current database server version. + * If the optional precision argument is passed, return the first prec + * fields of the full version number. + * + * @example + * var x = getPgVersion(1), // '9' + * xy = getPgVersion(2), // '9.1' + * xyz = getPgVersion(3), // '9.1.3' + * all = getPgVersion(); // '9.1.3' + * + * @param {Number} proc - optional precision + * @returns {String} X[.Y[.Z]] + */ + getPgVersion: function (prec) { + var q = plv8.execute("select setting from pg_settings " + + "where name='server_version';"), + ret; + ret = q[0].setting; + if (typeof prec === 'number') { + ret = ret.split(".").slice(0,prec).join("."); + } + return ret; + }, + /** * Get the oid for a given table name. * @@ -2399,12 +2424,14 @@ select xt.install_js('XT','Data','xtuple', $$ lockExp, oid, pcheck, + pgver = 0 + XT.Data.getPgVersion(2), pid = options.pid || null, - pidSql = "select usename, procpid " + + pidcol = (pgver < 9.2) ? "procpid" : "pid", + pidSql = "select usename, {pidcol} " + "from pg_stat_activity " + "where datname=current_database() " + " and usename=$1 " + - " and procpid=$2;", + " and {pidcol}=$2;", query, selectSql = "select * " + "from xt.lock " + @@ -2412,6 +2439,8 @@ select xt.install_js('XT','Data','xtuple', $$ " and lock_record_id = $2;", username = XT.username; + pidSql = pidSql.replace(/{pidcol}/g, pidcol); + /* If passed a table name, look up the oid. */ oid = typeof table === "string" ? this.getTableOid(table) : table; diff --git a/scripts/install_xtuple.sh b/scripts/install_xtuple.sh index ee2121be9..b8ae265c8 100644 --- a/scripts/install_xtuple.sh +++ b/scripts/install_xtuple.sh @@ -139,7 +139,10 @@ install_packages() { sudo add-apt-repository -y "deb http://apt.postgresql.org/pub/repos/apt/ ${DEBDIST}-pgdg main" sudo wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get -qq update 2>&1 | tee -a $LOG_FILE - sudo apt-get -q -y install curl build-essential libssl-dev postgresql-9.1 postgresql-server-dev-9.1 postgresql-contrib-9.1 postgresql-9.1-plv8 2>&1 | tee -a $LOG_FILE + sudo apt-get -q -y install curl build-essential libssl-dev \ + postgresql-${PG_VERSION} postgresql-server-dev-${PG_VERSION} \ + postgresql-contrib-${PG_VERSION} postgresql-${PG_VERSION}-plv8 2>&1 \ + | tee -a $LOG_FILE if [ ! -d "/usr/local/nvm" ]; then sudo rm -f /usr/local/bin/nvm @@ -154,10 +157,11 @@ install_packages() { sudo nvm alias xtuple $NODE_VERSION # use latest npm - npm install -fg npm@1.4.25 + sudo npm install -fg npm@1.4.25 # npm no longer supports its self-signed certificates log "telling npm to use known registrars..." npm config set ca "" + sudo chown -R $USER $HOME/.npm log "installing npm modules..." npm install --unsafe-perm 2>&1 | tee -a $LOG_FILE @@ -189,7 +193,7 @@ setup_postgres() { return 1 fi - PGDIR=/etc/postgresql/9.1/main + PGDIR=/etc/postgresql/${PG_VERSION}/main log "copying configs..." sudo cp $PGDIR/postgresql.conf $PGDIR/postgresql.conf.default diff --git a/scripts/lib/build_database.js b/scripts/lib/build_database.js index aa0b85c58..8ae4296d6 100644 --- a/scripts/lib/build_database.js +++ b/scripts/lib/build_database.js @@ -191,9 +191,8 @@ var async = require('async'), return memo + script; }, ""); - // Without this, when we delegate to exec psql the err var will not be set even - // on the case of error. - allSql = "\\set ON_ERROR_STOP TRUE;\n" + allSql; + // Without this, psql runs all input and returns success even if errors occurred + allSql = "\\set ON_ERROR_STOP TRUE\n" + allSql; winston.info("Applying build to database " + spec.database); credsClone.database = spec.database; diff --git a/scripts/xml/distribution_install.xml b/scripts/xml/distribution_install.xml index b82f1bd4d..0d32d935f 100644 --- a/scripts/xml/distribution_install.xml +++ b/scripts/xml/distribution_install.xml @@ -1,5 +1,5 @@ - @@ -19,8 +19,8 @@ - SELECT NOT fetchMetricText('ServerVersion') >= '4.7.0'; - This package may not be applied to a database newer than 4.7.0Beta. + SELECT NOT fetchMetricText('ServerVersion') >= '4.8.0'; + This package may not be applied to a database newer than 4.7.0. diff --git a/scripts/xml/distribution_package.xml b/scripts/xml/distribution_package.xml index 9ff6ab60f..0518ab715 100644 --- a/scripts/xml/distribution_package.xml +++ b/scripts/xml/distribution_package.xml @@ -1,5 +1,5 @@ - @@ -19,8 +19,8 @@ - SELECT NOT fetchMetricText('ServerVersion') >= '4.7.0'; - This package may not be applied to a database newer than 4.7.0Beta. + SELECT NOT fetchMetricText('ServerVersion') >= '4.8.0'; + This package may not be applied to a database newer than 4.7.0. diff --git a/scripts/xml/postbooks_package.xml b/scripts/xml/postbooks_package.xml index 041993b4a..464f2b819 100644 --- a/scripts/xml/postbooks_package.xml +++ b/scripts/xml/postbooks_package.xml @@ -1,5 +1,5 @@ - @@ -19,8 +19,8 @@ - SELECT NOT fetchMetricText('ServerVersion') >= '4.7.0'; - This package may not be applied to a database newer than 4.7.0Beta. + SELECT NOT fetchMetricText('ServerVersion') >= '4.8.0'; + This package may not be applied to a database newer than 4.7.0. diff --git a/scripts/xml/xtmfg_install.xml b/scripts/xml/xtmfg_install.xml index b6eb59595..3d34014cb 100644 --- a/scripts/xml/xtmfg_install.xml +++ b/scripts/xml/xtmfg_install.xml @@ -1,5 +1,5 @@ - @@ -19,8 +19,8 @@ - SELECT NOT fetchMetricText('ServerVersion') >= '4.7.0'; - This package may not be applied to a database newer than 4.7.0Beta. + SELECT NOT fetchMetricText('ServerVersion') >= '4.8.0'; + This package may not be applied to a database newer than 4.7.0. diff --git a/scripts/xml/xtmfg_package.xml b/scripts/xml/xtmfg_package.xml index ff787b40c..ef6ce2c99 100644 --- a/scripts/xml/xtmfg_package.xml +++ b/scripts/xml/xtmfg_package.xml @@ -1,5 +1,5 @@ - @@ -30,8 +30,8 @@ -SELECT NOT fetchMetricText('ServerVersion') >= '4.7.0'; - This package may not be applied to a database newer than 4.7.0Beta. +SELECT NOT fetchMetricText('ServerVersion') >= '4.8.0'; + This package may not be applied to a database newer than 4.7.0.