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

Control over migration script generation #35576

Open
yzinc opened this issue Feb 3, 2025 · 7 comments
Open

Control over migration script generation #35576

yzinc opened this issue Feb 3, 2025 · 7 comments

Comments

@yzinc
Copy link

yzinc commented Feb 3, 2025

Question

After migration to .net 9 I faced with unexpected result in migration script.
Context, I'm generating sql migration script using next command

dotnet ef migrations script --project <project-name> --configuration Release --idempotent --startup-project <start-up-project> --output migration.sql --context <context-name>

Using .net8 I get

migration8.txt

but, using .net9 I get

migration9.txt

All migrations performs in SINGLE transaction, with only ONE GO statement. I didn't found any information about this changes and how it can be reconfigured. Honestly those changes are breaking for my project and I forced to looking some kind of workaround.

Highly appreciate for any advice/information.

Your code

Stack traces


Verbose output


EF Core version

9.0.1

Database provider

No response

Target framework

No response

Operating system

No response

IDE

No response

@cincuranet
Copy link
Contributor

@maumar Do we have this documented somewhere? I see only Exception is thrown when applying migrations in an explicit transaction, which has basically same root cause. But for users it might not be clear that this affects script as well.

@roji
Copy link
Member

roji commented Feb 4, 2025

Dup of #35096? Though @yzinc it would be good to know exactly why the single transaction breaks your application.

@cincuranet
Copy link
Contributor

Not exactly dup, but related.

@yzinc
Copy link
Author

yzinc commented Feb 4, 2025

@roji Main issue is that all migration treated as single scope due to single batch and single transaction. So If you add some custom migration script with variable declaration, all variables accross all migrations have to be with unique names.

Here is example of exception I've got.

The variable name '@roleId' has already been declared. Variable names must be unique within a query batch or stored procedure.

More context, if some migrations need to be performed regulary due to some business needs or whatever. Usually some C# code are written to optimize this process and if variables declarations are required to perform such operations in each regular migration will have same variable name.

Previously it was not a problem due to own transaction and batch scope. But now it's a problem which do not allow to run migrations at all without some "hacks".

@roji
Copy link
Member

roji commented Feb 4, 2025

Thanks @yzinc.

@cincuranet how do you see this as different from #35096?

@cincuranet
Copy link
Contributor

AFAICT #35096 is not specifically about script.

@roji
Copy link
Member

roji commented Feb 4, 2025

I'm not sure this one is specifically about script either - AFAICT you'd encounter the exact same problem try to apply the migration in some other way (e.g. dotnet ef database update).. It seems to be just another example of something that doesn't work when the same transaction is used across all migrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants