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

Detecting script vs execution in MigrationsSqlGenerator #14746

Closed
cincuranet opened this issue Feb 20, 2019 · 13 comments · Fixed by #21933
Closed

Detecting script vs execution in MigrationsSqlGenerator #14746

cincuranet opened this issue Feb 20, 2019 · 13 comments · Fixed by #21933
Assignees
Labels
area-migrations breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 type-enhancement
Milestone

Comments

@cincuranet
Copy link
Contributor

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.

@ajcvickers
Copy link
Member

@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?

@cincuranet
Copy link
Contributor Author

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...

@ajcvickers
Copy link
Member

@bricelam to follow up.

@bricelam
Copy link
Contributor

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.

@cincuranet
Copy link
Contributor Author

cincuranet commented Feb 25, 2019 via email

@bricelam bricelam self-assigned this Feb 25, 2019
@bricelam
Copy link
Contributor

I agree, it wouldn't work for SET TERM.

@cincuranet
Copy link
Contributor Author

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.

@bricelam
Copy link
Contributor

Correct; there's currently no way to detect it.

@roji
Copy link
Member

roji commented Mar 21, 2020

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).

@bricelam
Copy link
Contributor

bricelam commented Aug 1, 2020

@roji I can't figure out what Npgsql actually needs to do differently in the script vs at runtime. Can you elaborate?

@bricelam
Copy link
Contributor

bricelam commented Aug 1, 2020

Oh I see--npgsql/efcore.pg#1157. So yours is only for idempotent too. (like SQL Server's #12911)

@bricelam
Copy link
Contributor

bricelam commented Aug 1, 2020

@cincuranet You need to do it for all scripts, right? (not just idempotent)

@cincuranet
Copy link
Contributor Author

cincuranet commented Aug 1, 2020 via email

bricelam added a commit to bricelam/efcore that referenced this issue Aug 4, 2020
Also adds the ability for providers to detected whether a script is being generated and whether its idempotent. (resolves dotnet#14746)

Fixes dotnet#12911
@bricelam bricelam added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. breaking-change labels Aug 4, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-rc1 Aug 14, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-rc1, 5.0.0 Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-migrations breaking-change closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-3.0 type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants