Handle from: {reference, opts} in FK migrations#511
Conversation
|
I tried to add a test to check if the Am I overlooking those? |
|
Above comment is not relevant anymore, I added a test for a rollback too 😄 |
|
Hi, Thanks for the PR. I'm not entirely sure this will work. For example, the Postgres docs say this 5.6.4. Removing a Constraint So it looks to me like this PR will drop the foreign key constraint but not the null constraint. |
|
Hey, Good find! I didn't think that would be relevant for this PR, because the # This is already possible in the current version of ecto_sql
modify :author_id, references(:authors), null: false
# This becomes possible by this PR, but is implicitly the same (correct me if I'm wrong :))
modify :author_id, references(:authors), null: false, from: {references(:authors), null: true}But to be sure, I added integration tests, and it seems ecto_sql already handles the However, the MySQL integration test may fail, because it's not possible to
It seems that the default |
|
I've adjusted the integration tests to migrate from a FK to an integer and back. This way the change in this PR is tested (passing It seems that the MySQL adapter currently can't handle migrating an existing FK column to another FK, I'll create a separate issue for that. Edit: I'm not sure why 1 check is failing, it's working locally and in my fork. Can someone try if restarting the check works? |
|
Sorry so what I meant was I don't think this works:
When it drops the old behaviour it will drop the foreign key constraint but not the |
|
BTW it's ok to leave out the integration tests. I believe I misspoke before about adding them and I edited my comment. We are basically just looking at the query string anyway which is what the unit test is doing. |
Actually I apologize, it's because in your unit test you are not setting a new
Then we can merge. Thanks! |
|
Using your example, the migration query for Postgres becomes: ALTER TABLE "comments" DROP CONSTRAINT "comments_author_id_fkey", ALTER COLUMN "author_id" TYPE bigint, ADD CONSTRAINT "comments_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "authors"("id"), ALTER COLUMN "author_id" DROP NOT NULLSo it does ALTER TABLE "comments" DROP CONSTRAINT "comments_author_id_fkey", ALTER COLUMN "author_id" TYPE bigint, ADD CONSTRAINT "comments_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "authors"("id"), ALTER COLUMN "author_id" SET NOT NULLIs this what you mean, or am I misunderstanding you here? Maybe I wasn't clear in what I'm trying to fix here. Passing the |
|
Ah okay, makes sense then! I'll fix the PR and let you know! |
|
Yeah I apologize I didn't look carefully enough at your unit tests. I thought you were passing |
|
No problem, I'm glad it's looking good now! 😄 The tests are fixed. |
|
Thanks! |
Fixes #510