-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Detecting script vs execution in MigrationsSqlGenerator #14746
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
@cincuranet We recommend not creating different output when generating a script as opposed to applying the migrations directly. Can you give some more details on why this is needed? |
Yes I can. When the migrations are generated and directly executed, it is known what's the command. But when I generate the script, then the semicolons are, by default, delimiting commands. But semicolons inside i.e. stored procedure will break the parsing and the script is not going to be valid (and Firebird, at the moment, does not support sending multiple commands inside one "packet"). That's why Firebird has SET TERM "statement" (it's really not a statement, because server does not handle it, it's purely for client side tools to handle parsing. That why the stored procedure in script would look like this for Firebird. -- changing the separator to ^
set term ^;
-- the end of the procedure is signaled by ^ so the ; can be used inside
create procedure ...
begin
foo;
bar;
baz;
end^
-- changing the separator back to ;
set term ;^ Yes, I know there are ways to handle it without explicit separators (like counting "begin-end" etc. levels), but none of this is supported by any - default or commercial - tool known to me supporting Firebird. If this would be easy to do, I would like to do it. Else, meh, let's see whether somebody asks for it... |
@bricelam to follow up. |
SQL Server has the GO utility statements for tools to mark the end of a batch/DbCommand. Does Firebird have a similar concept for tools? This is enabled by the ISqlGenerationHelper.BatchTerminator property. If not, we can look into adding a flag to indicate that Migrator.GenerateScript was called. |
Yeah, the GO is similar concept. But for Firebird it's not hardcoded. At the beginning the `SET TERM xxx` has to be called. And only for scripts and procedural blocks.
So I fail to see how the `BatchTerminator` could be used, but I might be missing something.
|
I agree, it wouldn't work for |
So the state is that ATM I can't detect that the script is being generated, right? I'll leave it as it's now and once the flag is present - I suppose somewhere in 3.x timeframe - I'll update the code. |
Correct; there's currently no way to detect it. |
Note: this has become more critical for Npgsql - am going to need this for automatic sequence reset after seeding to avoid collision (npgsql/efcore.pg#367). |
@roji I can't figure out what Npgsql actually needs to do differently in the script vs at runtime. Can you elaborate? |
Oh I see--npgsql/efcore.pg#1157. So yours is only for idempotent too. (like SQL Server's #12911) |
@cincuranet You need to do it for all scripts, right? (not just idempotent) |
Correct.
|
Also adds the ability for providers to detected whether a script is being generated and whether its idempotent. (resolves dotnet#14746) Fixes dotnet#12911
Is there an easy way to detect whether the
XxxMigrationsSqlGenerator
is generating statements for execution or for script to be created? Because for script I have to generate slightly different output for user to be able to execute it without minor tweaks (basically SET TERM).If not, it's fine. In EF6 this wasn't done either and nobody complained. As one would expect people run the migrations directly.
The text was updated successfully, but these errors were encountered: