graphql-engine: Error: Cannot use database previously used with a newer version of graphql-engine (expected a catalog version <=36, but the current version is 37). , code : not-supported

Hello everyone. I’m getting this error on my Heroku app:

Cannot use database previously used with a newer version of graphql-engine (expected a catalog version <=36, but the current version is 37

graphql-engine version: v1.3.0 Postgress DB version: v12.3

I did open an issue on the graphql-engine-heroku (link: https://github.com/hasura/graphql-engine-heroku/issues/84), but I’m opening an issue in here for reasons explained down below.

When version 1.3.0 got released, it broke my Hasura app console on Heroku. I managed to fix the problem by running the following commands:

git pull #Get the latest Docker Image
heroku git:remote -a <my-app>
heroku stack:set container -a <my-app>
git push heroku master

But yet again, (since Friday 31/7/2020), the same problem occurred, and this time, I’m having zero luck fixing this issue.

The problem is that with every release, my Heroku app keeps breaking because of my catalog version (which I don’t even touch at all), and I’m sure that’s not the expected behaviour. Soo that’s why I think it’s worth opening an issue in here.

I tried migrating, but whenever I try to access the API, it spills out that error, soo in result, I can’t do anything through the Hasura CLI, which eliminates any other solution that can be done with the Hasura CLI.

Complete error:

{"kind":"db_migrate","info":{"path":"$","error":"Cannot use database previously used with a newer version of graphql-engine (expected a catalog version <=36, but the current version is 37).","code":"not-supported"}}}

I don’t even know why it is using version 37, I didn’t touch a single thing.

Thanks! I reported this issue on Discord as well, and it appears to be that I’m not the only one who went through the same problems since v1.3.0 release.

Heroku’s message whenever I try to access the console: image

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (3 by maintainers)

Most upvoted comments

Something is odd here (did you check cloud.hasura.io? ). The image here: hasura/graphql-engine-heroku is not ahead of v1.3.0 hence it seems unlikely that it may have pulled and deployed a newer version.

Downgrade will not work because catalog 37 is ahead of v1.3.0 and hence it doesn’t know how to downgrade.

Anyway, here is the sql to update your catalog to 36. Then v1.3.0 should run safely:

BEGIN;

CREATE OR REPLACE FUNCTION 
  hdb_catalog.insert_event_log(schema_name text, table_name text, trigger_name text, op text, row_data json)
  RETURNS text AS $$
  DECLARE
    id text;
    payload json;
    session_variables json;
    server_version_num int;
  BEGIN
    id := gen_random_uuid();
    server_version_num := current_setting('server_version_num');
    IF server_version_num >= 90600 THEN
      session_variables := current_setting('hasura.user', 't');
    ELSE
      BEGIN
        session_variables := current_setting('hasura.user');
      EXCEPTION WHEN OTHERS THEN
                  session_variables := NULL;
      END;
    END IF;
    payload := json_build_object(
      'op', op,
      'data', row_data,
      'session_variables', session_variables
    );
    INSERT INTO hdb_catalog.event_log
                (id, schema_name, table_name, trigger_name, payload)
    VALUES
    (id, schema_name, table_name, trigger_name, payload);
    RETURN id;
  END;
$$ LANGUAGE plpgsql;

UPDATE hdb_catalog.hdb_version SET version = 36;

COMMIT;

I would again make sure to check cloud.hasura.io for any project. Hasura Cloud runs with catalog 37 and hence that seems the mostly likely source of this upgrade.

@tirumaraiselvan running in to this now upgrading from v2.0.0-alpha.7 => v2.0.0-alpha.8 and while the script above seems to be helpful, why is it necessary to have to do this? what are the ramifications of running this manually? Why is this not handled by hasura itself…

Surely there can’t be an expectation that every time hasura is updated an entire new db is created.

This has now been fixed with v1.3.1. You can use Heroku and Hasura Cloud on the same DB.

I confirm the script fixes the issue! 🎉

Just a small thing, the last line should use semicolon COMMIT; instead of a colon :

@followbl - this is a separate issue. We are tracking in: https://github.com/hasura/graphql-engine/issues/6802

Hi @tirumaraiselvan

I’m pretty sure I didn’t do anything on the DB nor on the Hasura console itself, my Heroku app simply stopped working (on Friday), and this has happened twice already.

I’m guessing maybe Heroku pulled down the Docker image from the hasura/graphql-engine-heroku and updated the Hasura metadata with that new image (by itself), which then cause the catalog version to be updated to 37, but that just a wild guess.

The SQL will be greatly appreciated. Thanks!

@LuisDev99 Did you point your DB to a Hasura Cloud project? Or did you run some PR build on the same database?

Catalog version 37 was introduced in master after v1.3.0 (which is at 36) and your database getting migrated to catalog version 37 means that some newer version of Hasura was run on the same database.

To fix this, we can send you a SQL to downgrade manually from 37 to 36 and then v1.3.0 will be compatible with your database state again.