-
Notifications
You must be signed in to change notification settings - Fork 73
fix(graphql-migrations): set primary keys when a column has @id
#1421
fix(graphql-migrations): set primary keys when a column has @id
#1421
Conversation
8fe60a7
to
86ec94b
Compare
2b1f0ee
to
845d890
Compare
I think our initial design was that PK was never actually applied. When using primary - confusing name - you got sequence for id and if it something else you should get unique only. This is due to the format of the data. You can set primary/id on username and this primary is not considered and primary key - it is more like I'd that will be used for queries. Also enda question nailed the root of the problem. Incementability is not exacly going to work with any type - especially not numeric one like email etc. |
Hi @wtrocki thanks for chimming in. Really good points you raised here.
So you are saying that we basically should not be setting primary key constraint? What should be done when the
Wel, that's it in this patch I am not increment any other type but only the
The only effect that the graphback/packages/graphback-runtime-knex/tests/service/DefaultCRUDServiceTest.ts Line 134 in 845d890
|
ok. so you have it figured out and fix seems to addressing main challenges. Lets have great evening and relax. I will verify this for you tommorow |
Yes, this is what I have when I ran the migration with for the model below: model
database
Now, going back to the PR description:
The error described here is that we cannot automatically infer a primary key because we always seem to be defaulting to So have to explicitly specify foreign key using the |
I've done some quick verification checks. Graphback allows you to set """
@model
"""
type User {
id: ID!
"""
@id
"""
email: String
} The model above (which would be acceptable in Graphback, throws the following error in migrations:
Perhaps There appears to be a problem when trying to add new columns after first migration. """
@model
"""
type User {
"""
@id
"""
email2: String
email3: String
} The above model performs a migration as expected.
However an error occurs when I added a new regular field
For some reason it tries to drop email2, even though I have not made any change to it. |
Very good point.
Yeap, I have encountered the issue too. I suppose the change I have added in the computeDiff are not enough, I am looking at it now. |
Fully agreed. Feedback suggests fewer annotations needed the better (and rightly so) |
Thanks for the linked issue for this. Totally agree. |
845d890
to
9cb1fd3
Compare
Checking this out locally now. |
It appears that changing the field annotated with """@id""" after the first migration does not update the database primary key. Do you see this too @machi1990?
I don't know if this is fixable, as long as the error is thrown though it is probably fine. Perhaps we should add this as note to website documentation? |
Ah strange as this should have been addressed by https://github.com/aerogear/graphback/pull/1421/files#diff-4972a24a7bb3dda74ca34232ed6243aeR304
From the test I did, looks like the code I shared above fixed it Might have been a false positive. Let me keep on looking and if not fixable I can add a note in the documentation as suggested. |
40105f3
to
2c79d96
Compare
@craicoverflow I have pushed new changes hoping to fix the |
2c79d96
to
37f63bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small comment here https://github.com/aerogear/graphback/pull/1421/files#r440061816
Other than that, this is great!
Co-authored-by: Enda <ephelan@redhat.com>
Fixes #1397
Opening as draft to get early feedback but from what I am seeing the
@id
or its predecessor@db.primary
never really worked before.Here is what I mean, apart from the primary field not being set, which should be fixed by this patch, another issue is when you have a relation like the one we have in https://github.com/aerogear/graphback/blob/24894c385f1ad846312c9382dae5468f98dc1f73/templates/ts-apollo-postgres-backend/model/datamodel.graphql where the migration will fail with the below error:
as it still expects the
id
to be a primary field. I'd consider that a separate issue and I can investigate further once we are okay with this patch./cc @craicoverflow