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

Add rename primary and foreign key operation #14988

Closed
wants to merge 3 commits into from

Conversation

Brar
Copy link

@Brar Brar commented Mar 11, 2019

Addresses #5662

I've kept separate commits for the three different constraint types but will squash them upon request.

  • The code builds
  • All but 2 tests pass (verified by running .\build.cmd -test on my system). The 2 failing tests seem to be completely unrelated to my changes as they also fail on a clean master checkout on my system:
    • Microsoft.EntityFrameworkCore.Scaffolding.SqlServerDatabaseModelFactoryTest.Default_value_matching_clr_default_is_not_stored fails for IgnoredDefault24 float NOT NULL DEFAULT 0.0E0 where null is expected and the actual value is 0.000000000000000e+000
    • Microsoft.EntityFrameworkCore.Scaffolding.SqlServerDatabaseModelFactoryTest.Hidden_columns_are_not_created throws an SqlException : Incorrect syntax near 'GENERATED'.\r\nIncorrect syntax near 'HIDDEN'.\r\nIncorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
  • Commit messages currently don't follow this format as they aren't finalized yet
    Summary of the changes
    - Detail 1
    - Detail 2

    Fixes #bugnumber

Please review the guidelines for CONTRIBUTING.md for more details.

@Brar
Copy link
Author

Brar commented Mar 11, 2019

Sorry this was meant to be a Draft pull request but I accidentally created a normal one and it appears that you cant change this after it has been created (I've actually already bugged @natfriedman about this on twitter).

@bricelam bricelam self-assigned this Mar 13, 2019
@bricelam bricelam changed the title Add rename primary and foreign key operation [WIP] Add rename primary and foreign key operation Mar 13, 2019
@Brar Brar force-pushed the AddRenamePrimaryAndForeignKeyOperation branch from bf2d695 to c4f97dc Compare May 3, 2019 15:56
@Brar
Copy link
Author

Brar commented May 3, 2019

I've rebased this because it didn't apply cleanly anymore.
As rebasing while keeping several commits in order is a pain, I've also squashed the commits into one single commit.

@Brar Brar force-pushed the AddRenamePrimaryAndForeignKeyOperation branch from c4f97dc to 38b9f09 Compare May 3, 2019 16:20
Copy link
Contributor

@bricelam bricelam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a few comments...

@ajcvickers
Copy link
Member

@Brar Just wanted to let you know that we haven't forgotten about this. However, due to other high-priority work it make take a bit of time for us to get back to this.

@Brar
Copy link
Author

Brar commented May 10, 2019

@ajcvickers thanks, no worries.
I'll try to come up with a suggestion addressing the comments.
We can pick up the discussion at that point as soon as you get to it.

@bricelam
Copy link
Contributor

Also remember that today they generate drop and re-create operations so they would be no more broken than they already are. We have a separate issue to perform table and constraint rebuilds automatically as part of a migration.

@Brar Brar force-pushed the AddRenamePrimaryAndForeignKeyOperation branch from 38b9f09 to 834d4d7 Compare May 11, 2019 20:33
@Brar
Copy link
Author

Brar commented May 11, 2019

Ok, this is my suggestion for further discussions.
There are still some areas in the code, where I'm uncertain, if my chosen solution is the best way to do it or even appropriate.
I've commented them in the code but I'll also list them here so that they don't get lost.

  1. I had to move an IMigrationsAnnotationProvider down one level in the inheritance chain to src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs in order to be able to create annotations at this level. Please also look at the default instance and its MigrationsAnnotationProviderDependencies.
  2. The default implementation of RenameForeignKeyOperation in src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs will reset the OnUpdate ReferentialAction to its default value.
  3. I decided to still throw from the Generate overrides for the rename operations in src/EFCore.Sqlite.Core/Migrations/SqliteMigrationsSqlGenerator.cs because Sqlite doesn't currently support the add operations for primary/foreign keys and unique constraints so drop/create isn't an option here until Sqlite Migrations: Table rebuilds #329 has landed.
  4. I'm uncertain if the exception message thrown from the Generate methods for the rename operations in src/EFCore.Relational/Migrations/MigrationsSqlGenerator.cs is the right one.

@bricelam bricelam added this to the 5.0.0 milestone Oct 9, 2019
@Brar
Copy link
Author

Brar commented Dec 8, 2019

@ajcvickers @bricelam Now that 3.1 is out and you are beginning to work on 5.0 I assume that it's a good time for me to lobby for this PR again.
I'm willing to rebase it once again if there is time and dedication to review and possibly merge it in a timely manner.
Please go ahead and tell me if I should wait a litte and when it would best fit into your schedule. I just want to avoid working into the void.

cc: @roji

@bricelam
Copy link
Contributor

bricelam commented Dec 9, 2019

I hope to get this in before the first preview of of 5.0.0. It might be early January before I get around to it. (I'm currently writing some docs to support the 3.1 release.)

@Brar
Copy link
Author

Brar commented Dec 9, 2019

Thanks @bricelam!
No hurry.
I'll rebase it in the next few weeks so that it's ready for re-review by January.

@Brar Brar force-pushed the AddRenamePrimaryAndForeignKeyOperation branch 2 times, most recently from 134cbcf to 4052c41 Compare December 13, 2019 18:17
@Brar Brar requested a review from bricelam December 13, 2019 20:41
@Brar
Copy link
Author

Brar commented Dec 13, 2019

@bricelam I've rebased this as I had some spare time today.
Don't feel pressured - January is fine!

Copy link
Contributor

@bricelam bricelam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just need to clean up the breaking changes and use our dependency object patterns.

@Brar Brar force-pushed the AddRenamePrimaryAndForeignKeyOperation branch from 734be68 to 3887916 Compare January 29, 2020 20:46
@bricelam bricelam changed the title [WIP] Add rename primary and foreign key operation Add rename primary and foreign key operation Jan 29, 2020
Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New migration tests look great to me, thanks @Brar!

I think we can drop the ModelDiffer and MigrationSqlGenerator tests - the new migration tests exercise all those components as well, so these don't add any value. We still have these two test suites for tests which for some reason cannot be tested in MigrationsTestBase (#19668 is about cleaning that up). @bricelam can you confirm you're OK with that?

Other notes:

  • Some tests are failing (at the very least some SQL baselines need updating)
  • If we're adding rename support for constraints, we may as well do the same for checked constraints...
  • I haven't reviewed anything else here other than the tests

@Brar Brar force-pushed the AddRenamePrimaryAndForeignKeyOperation branch from 3887916 to 5b58bb0 Compare January 29, 2020 22:25
@Brar
Copy link
Author

Brar commented Jan 29, 2020

Some tests are failing (at the very least some SQL baselines need updating)

Sorry this was my fault.
After 3 Visual Studio crashes while trying to run more then one test at once, I decided to push this and hope for the best, which - as we all know - never goes well.

I think we can drop the ModelDiffer and MigrationSqlGenerator tests

I haven't removed anything yet, but I can certainly do so. Just waiting for @bricelam to confirm that he's OK with that.

If we're adding rename support for constraints, we may as well do the same for checked constraints

👍

@bricelam
Copy link
Contributor

Sounds good to me

@Brar Brar force-pushed the AddRenamePrimaryAndForeignKeyOperation branch from 5b58bb0 to 098934d Compare February 22, 2020 09:21
@Brar
Copy link
Author

Brar commented Feb 22, 2020

Hi @bricelam and @roji
sorry for the delay.
A skiing-holiday and my day-job threw me back a little but now I think I've addressed all your feedback.

While most of the changes are pretty straightforward, I urge you to have a closer look at the last commit regarding the warning.
I'm by no means confident, that what I did there is the way it should be done.

@Brar Brar requested a review from bricelam February 22, 2020 13:06
@smitpatel
Copy link
Contributor

skiing-holiday

@Brar - Skiiing always takes priority over anything else.

@bricelam bricelam removed this from the 5.0.0 milestone Feb 28, 2020
@Brar Brar force-pushed the AddRenamePrimaryAndForeignKeyOperation branch from 453cfe0 to 5169298 Compare March 12, 2020 17:06
Brar added 3 commits May 9, 2020 01:05
Some database systems support renaming primary key constraints, foreign
key constraints or unique constraints without rebuilding the table.
Add the following operations to MigrationBuilder in order to support
this:

- RenamePrimaryKeyOperation
- RenameUniqueConstraintOperation
- RenameForeignKeyOperation
@Brar Brar force-pushed the AddRenamePrimaryAndForeignKeyOperation branch from 5169298 to eafed8b Compare May 8, 2020 23:33
@Brar
Copy link
Author

Brar commented May 9, 2020

Ok @bricelam, I've rebased this once again.
Actually I've deemed it ready for another review since Feb 22 but I'm not sure that this has really come across.
As someone told me, the logging part is a no-go-area that only @ajcvickers dares to enter so he might want to have a look at the last commit where I attempt to do something I don't completely understand.

@ajcvickers ajcvickers assigned ajcvickers and unassigned bricelam Jun 16, 2020
@microsoft-github-updates microsoft-github-updates bot changed the base branch from master to main July 23, 2020 04:35
@bricelam bricelam assigned bricelam and unassigned ajcvickers Aug 25, 2020
@Brar
Copy link
Author

Brar commented Dec 9, 2020

Since this has been inactive for quite a while and I don't think I can resume working on this any time soon I'm closing this now.

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

Successfully merging this pull request may close these issues.

5 participants