xTuple.com xTupleU Blog & News Customer Support

Upgrade 4.4.0->4.9.2, ERROR: function "xt.js_init" does not exist

Hi,

I am trying to upgrade from 3.8.4 to 4.4.0 and then jump to 4.9.2.
I can get to 4.4.0 but when I try to jump to 4.9.2, I get an error about a non existent xt.js_init function. I do not have an xt schema in my database and I cannot seem to find out how I can get it.

I am using Postgres 9.4 with plv8 on Ubuntu 14
The prerequisite checks all pass (I am using xTuple Updater 2.2.5, same thing happens with 2.4.0) but when hit the start button for the upgrade, I get the message: ERROR: function “xt.js_init” does not exist.

Where does the xt schema come from?

Thanks.

@hsp,

You are seeing a chicken-and-egg problem. In geek speak: there’s a forward reference error - the Updater cannot create the xt schema and xt.js_init() function because these objects don’t yet exist.

You should be able to fix this by running the following SQL:

-- xtuple/lib/orm/source/create_xt_schema.sql
do $$
declare
  count integer;
  query text;
begin
  /* Only create the schema if it hasn't been created already */
  perform *
  from information_schema.schemata 
  where schema_name = 'xt';

  get diagnostics count = row_count;

  if (count > 0) then
    return;
  end if;

  query = 'create schema xt;';
  execute query;

  query = 'grant all on schema xt to group xtrole;';
  execute query;

end;
$$ language 'plpgsql';

-- xtuple/lib/orm/source/create_plv8.sql
-- dummy function avoids forward reference bug with some plv8 versions
CREATE OR REPLACE FUNCTION xt.js_init(debug BOOLEAN DEFAULT false, initialize BOOLEAN DEFAULT false)
RETURNS VOID AS $$ BEGIN RETURN; END; $$ LANGUAGE plpgsql;

CREATE EXTENSION IF NOT EXISTS plv8;

I’ll work with other folks here to document this properly.

Gil

Thank you for the quick response Gil, that fixes the error.

We have a similar problem trying to upgrade from 4.10 to 4.11.1, only our error message is more open ended. We get the following;

ERROR: SyntaxError: Unexpected token ILLEGAL
DETAIL: js_init() LINE 1
(XX000)
QPSQL: Unable to create query

Hi,

If you open the script in notepad++, for example, can you make sure the encoding is set to utf8 and not utf8-BOM (or something else). I have noticed that I get some weird characters in my scripts sometimes and it is because of the encoding. I was able to see the weird characters in the design ->scripts of the xTuple (my script was part of a package that I made).

Mike,

Try the upgrade on a test database with the Updater 2.5.0 Beta. If that runs as expected then you should be able to pilot 4.11.1 with the resulting database. Typically I would not recommend using a pre-release in a production or semi-production environment, but we did find a likely fix (related to BOMs as Harjit said) and incorporated it into this Updater beta.

Another user has reported that sometimes the Unexepcted token problem goes away if you try rerunning enough times without restarting the Updater:

  1. start the Updater
  2. File > Open
  3. select the 4.11.1 upgrade package
  4. START UPDATE
  5. if the update fails then go back to step 2

Gil

Hi, Mike:

Have you tried running the SQL script that Gil referred to previously? Here’s a link to an FAQ describing it in more detail:

https://xtupleuniversity.xtuple.com/library/faqs/how-do-i-fix-error-function-“xtjsinit”-does-not-exist-when-upgrading-xtuple-erp-v4x

Does that help with the upgrade problem?

Let us know!

Best regards,
Pierce

Thanks Pierce.
It took some doing, but we got it.