-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Data in enum tables should be tracked in console-generated migrations #2817
Comments
GraphQL enums must contain at least one value, according to the specification:
So insert at least one value into your enum table before marking it as an enum. |
I believe the issue is mixing two separate things. You can definitely have foreign key constraints involving an empty table (whether enum table or not). I am curious to know if there was any error which made you believe otherwise. The root problem here seems to be that you cannot have an enum table with no rows. The ideal flow for this would be as follows:
This will ensure that applying migrations won't break. Will be adding this to the docs as well. |
Thanks, @rikinsk I've created an intermediate migration with an insert. Although I wanted to have the values in the enum table to be dynamically created (by the admin or someone who takes care of the backend), I guess I am fine with the migration as long as it works! Although not related to this, but how do I automatically track the foreign key relations. I'm not sure if I have to pass any env, but I couldn't find any. It seems it is not automatic, as I read from #2726 ? |
@shugydw The insert migration is a necessity as the GraphQL spec doesn't allow defining GraphQL enums without any values. I guess you could simply have a dummy placeholder value inserted via migrations to begin with which can then dynamically be updated. Regarding automatically tracking foreign key relations, if I understand your requirement correctly, you can check out the thread at #1418 (and upvote to push it forward :)). I hope that is the use-case you were looking for. |
Responding to a comment @rikinsk13 made on slack:
I’ve been thinking about this, too. It sounds like it’s been more of a hiccup for people than I expected it to be, so it would be nice to somehow avoid the need to worry about it. Here are my current thoughts:
|
So far in our metadata system, we don't have anything which fails silently and I think we should aim to keep that up unless it is detrimental.
My biggest concern is that if we relax the schema generation, the same metadata could generate different GraphQL schema based on the data in the tables which I don't think is a good idea. Instead, adding such enums should fail and I completely agree with this:
We should just improve the console experience for this:
|
I agree. This feels like a bit of a gray area, though, since there’s really nothing morally wrong with a type that is not inhabited, and there’s no way for it to break any kind of data integrity were it allowed. The only problem is that GraphQL does not provide any support for uninhabited types. In general I share your instinct that reporting an error is much better than trying to implement some kind of DWIM interpretation. I don’t really like any of the “solutions” I listed, and I’d be reluctant to implement any of them. I just also sympathize with the constraint feeling a little artificial.
I think this is already the case, as the actual values of the enum are not stored in the metadata, they’re stored in the tables. However, that’s admittedly a smaller kind of difference than changing a column to an entirely different type.
I agree! |
#1766 has already been requested for similar purposes |
To add to this, it would be great if My current workaround is to simply keep a separate file around with all the sql insert statements for inserting the enums and copy pasting that to the end of the created init file. So it is not the most urgent thing, as resetting migrations is something done rarely, but a good quality of life thing, so nobody will get confused after resetting his migrations. |
Ran into this issue today, deploying with auto-migrations image from k8s caused the Hasura instance to fail due to the enums breaking everything. If I could make a suggestion @lexi-lambda, I think one of the easier ways to solve this issue would be to bundle the rows in the enum table as part of the migration (essentially a seed), since the Hasura enum spec defines that there must exist at least one entry in the table for it to be valid. |
Yes, I agree. I think that we should treat DML changes to enum tables as if they were DDL changes (since they morally are), and they should go in the console-generated migrations. I think it makes sense to repurpose this issue as a feature request for that feature, so I’ll do that. |
@Inch4Tk I made this because I don't want to bother keeping track of changes of my rows. This is basically my hacky workaround while there is no official seeding functionality in Hasura. I intend to use this to help migrate data from my local Docker server to a cloud one, mainly part of my DevOps pipeline. I haven't actually gotten there yet, but knowing that I have this command to automate obtaining data, makes it a little more easier to seed data to the production server.
Usage: Replace I could probably extend the command so that it can do this automatically too, but I'm still trying to figure out my workflow, so I guess I'll settle with having to copy and paste it for now. If anyone wishes to extend the command, feel free to do so. |
Data in enum tables should be exported while exporting the migrations from server using cli |
@shahidhk Thanks for the update! I have a few questions regarding this:
|
Second what @Inch4Tk has said. However, I do see one potential issue which is that sometimes the enum might grow overtime in a way that isn't desirable to include in squashed migrations. I think making an addition flag on enum tables: "Include Data in Migrations" or something would be a good middle ground. |
The ability to include data in migrations as a flag |
@GavinRay97 thanks! it would be nice if |
The console side of the issue is solved by #4993 and will be out in the next release (v1.4). Since this issue is primarily a discussion around this I am closing it. The CLI side of the issue (enum rows while initializing migrations using |
Is there any way in which I can directly mark a table as an enum (using migrations) without having to do it manually via the console? |
Version: Beta.6
Image: Docker CLI Migrations
Platform: K8s
Host: macOS Mojave
The new Enum table seems it requires at least one row - to be able to be connected foreign key constraint. It breaks migrations as well.
Here is an excerpt from the logs:
Thanks!
The text was updated successfully, but these errors were encountered: