graphql-engine: Migration fails because the enum needs at least one row, but my data has rows?
I’m trying to migrate data from Heroku to Docker, following the guide from here https://docs.hasura.io/1.0/graphql/manual/migrations/existing-database.html.
This is what I get when I run hasura migrate apply --endpoint http://localhost:8080:
FATA[0002] apply failed: [constraint-violation] the table "frequency" cannot be used as an enum because the table must have at least one row ($.args[2].args.tables[4])
Additional information:
- The table
frequencydoesn’t have zero rows, it actually has 10 rows, at least that’s what I see on the original Heroku db that I ranhasura migrate createfrom. frequencyisn’t the only enum table, nor was it the first one that was created. I had another enum calledarchive_typesand this was created first and is alphabetically earlier thanfrequency. This enum table also has values, but the console error doesn’t seem to mention it. Why would Hasura complain that that is something wrong withfrequencybut not witharchive_types?- The only thing I did past
hasura migrate create "init"was just create a test table, as stated in the guide.
Also I checked the files generated by the hasura migrate create "init" command, and it only seems to contain data about the whole Graphql/postgres schema itself (both the yaml and sql file). It doesn’t even contain a single actual row, i.e. my test data. Is there a way to migrate the data themselves too? It seems like migration isn’t that useful if it can’t do this.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 17 (4 by maintainers)
@joshuarobs This should work (while we fix this with something better):
hasura migrate create "init" --from-serverpg_dump <postgres-url> --column-inserts --data-only -t frequency -t archive_types >> 15xxxx_init.sqlhasura migrate apply --endpoint prod-endpoint.comYou can add multiple -t flags for all the enum tables. Hope this helps!
this really needs a fix. It’s troublesome if you create the migration after making the enum tables or when refreshing the migration from scratch.
I’m not sure if this is the best approach, but i’m leaving it here incase others may run into this issue, and for further discussion of potential better options.
Currently I use this shell script to generate a unique migration that combines all migrations, but appends enums at the end. The result is that when applying this to a new fresh hasura server, everything works fine and the server has the bare minimum data it needs to operate. User generated data is not included.
I’m currently WIP making this approach work in a production setting alongside CI/CD and I’m unsure if its optimal.
You’ll need a
seed-tablesfile in the same folder asconfig.yamlin thehasura/folder. An example I have is:It’s just a text file with a list of tables that I consider enums. Most of these tables are considered enum tables within Hasura, but some are enum-like which aren’t technically enums under hasura, but essentially act like an enum. In order to cater to this flexibility that I need, I put all the tables names that are considered enum-enough in this
seed-tablesfile.Running the script should work in my
projectdirectory, which has aproject/hasurafolder with all my hasura stuff in it. If it works without error, a new migration should be created in themigrationsfolder and you can find appended to the end of the file, all the seed data that the server needs. When applying this to a new fresh instance of a server, it loads all essential data for the server to work.