Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #5511

Closed
LuisDev99 opened this issue Aug 2, 2020 · 16 comments

Comments

@LuisDev99
Copy link

LuisDev99 commented Aug 2, 2020

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: hasura/graphql-engine-heroku#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

@tirumaraiselvan
Copy link
Contributor

tirumaraiselvan commented Aug 3, 2020

@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.

@LuisDev99
Copy link
Author

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
Copy link
Author

Update: I followed the Hasura downgrade steps listed here: https://hasura.io/docs/1.0/graphql/manual/deployment/downgrading.html#downgrade-hge

But it didn't work for me.

@tirumaraiselvan
Copy link
Contributor

tirumaraiselvan commented Aug 3, 2020

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.

@LuisDev99
Copy link
Author

Omg yes! The SQL worked!
It wasn't working at first because I had to restart the dyno.

Something is odd here (did you check cloud.hasura.io? ).

Nope, anything. My Hasura console on Heroku simply stopped working. No administration nor configuration was done on either the console or the DB.

The first time this same exact problem happened was during the v1.3.0 release, and later on, this past Friday. I noticed that on Friday (31/7/2020), commits were done to master, which is exactly by the time in which my console stopped working.

Maybe a regression was introduced? I don't really know. But I do know that the catalog shouldn't be ahead of it's intended working version every time something gets released or change. Again, it's weird because no configurations were done on my end. Didn't even use the console during those days, soo something is definitely off.

@LuisDev99
Copy link
Author

LuisDev99 commented Aug 3, 2020

Wait, you are right @tirumaraiselvan.

I remembered trying out the Hasura cloud about a month or two, and out of curiosity, I just went ahead and log in, and I'm seeing that my Heroku Postgres DB is being used by the project I created on the Hasura cloud, which is strange because I don't remember configuring the DB in there lol.

Soo, in other words, I created a project on the Hasura cloud, which was using the same DB as my app on Heroku (not good), which was causing all of these catalog version errors. Hope this helps!

Thank you very much @tirumaraiselvan

@m3hari
Copy link

m3hari commented Aug 5, 2020

I confirm the script fixes the issue! 🎉

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

@thgh
Copy link

thgh commented Aug 12, 2020

I also tried out Hasura Cloud and broke the console on Heroku. Thanks for the fix!

@tirumaraiselvan
Copy link
Contributor

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

@darrensapalo
Copy link

Just want to add here: This same issue can occur when you do a naive backup of your database data (e.g. Production hasura graphql is running v1.3.3), and import onto an outdated graphql service (e.g. local docker-compose running v1.3.2).

In my case, the above was what happened, and hasura won't start because it gave the following error:

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

In that specific case, the error translates to my local-machine's Hasura service saying: "My current version (1.3.2) expects a postgre DB with a hasura version of less than 37, but surprisingly the db says its 40. Because I am outdated, I don't know how to deal with the data, so I will not start".

In this specific case, the fix is to upgrade my target environment's hasura to match the current version from your source environment (1.3.2 to 1.3.3) on the docker-compose.yaml.

@courtneyholcomb
Copy link

@darrensapalo had the same issue and this fixed it! Thank you!

@followbl
Copy link

@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.

@followbl
Copy link

full error message

{"type":"startup","timestamp":"2021-04-20T05:06:34.349+0000","level":"error","detail":{"kind":"catalog_migrate","info":{"path":"$","error":"Cannot use database previously used with a newer version of graphql-engine (expected a catalog version <=46, but the current version is 45).","code":"not-supported"}}}

@tylerhannan
Copy link

@followbl - this is a separate issue. We are tracking in: #6802

@kiley0
Copy link

kiley0 commented May 12, 2023

Running into this error in my staging environment after copying database from prod to staging. Running both on Heroku.

Cannot use database previously used with a newer version of graphql-engine (expected a catalog version <=47, but the current version is 48).

Updated the Hasura GraphQL engine on staging to latest by pulling from git and pushing to Heroku. That fixed the issue everything was working. Same thing happened on prod after the next deployment. Had to updated prod as well. Now both staging and prod are using Hasura v2.25.0.

But then the next time I pushed new code, the error above reappeared and Hasura is not working. And now, even when I try to update the Hasura GraphQL engine, it says everything is up-to-date and remains in a broken state.

Any ideas?

@Balaji-654
Copy link

Running into this error in my staging environment after copying database from prod to staging. Running both on Heroku.

Cannot use database previously used with a newer version of graphql-engine (expected a catalog version <=47, but the current version is 48).

Updated the Hasura GraphQL engine on staging to latest by pulling from git and pushing to Heroku. That fixed the issue everything was working. Same thing happened on prod after the next deployment. Had to updated prod as well. Now both staging and prod are using Hasura v2.25.0.

But then the next time I pushed new code, the error above reappeared and Hasura is not working. And now, even when I try to update the Hasura GraphQL engine, it says everything is up-to-date and remains in a broken state.

Any ideas?

Did you got the solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants