Skip to content

Can't change from SERIAL to IDENTITY columns in idempotent migrations #1157

Closed

Description

@roji

Originally raised in #1089, attempted fix in #1092 broke non-idempotent migrations, so we're reverting it in #1156.

Our idempotent scripts run under PL/pgSQL, whereas non-idempotent scripts run in plain SQL. Unfortunately, when executing a function whose return value should be discarded, in PL/pgSQL we need to use PERFORM, whereas regular SQL requires SELECT. At the moment we can't distinguish between idempotent and non-idempotent in the migrations generator (dotnet/efcore#19250).

Another solution to this would be to run all migrations under PL/pgSQL.

Activity

  1. added this to the 5.0.0 milestone on Dec 9, 2019
  2. self-assigned this
    on Dec 9, 2019
  3. Slaviusz commented on Jan 21, 2020

    @Slaviusz

    Is there any known workaround? Proposed downgrade to 3.0.1 does not work and we're currently blocked moving on from .NetCore 2.2 to 3.1 migration within our project because of migrations failing from SERIAL to IDENTITY with PERFORM.

  4. roji commented on Jan 21, 2020

    @roji
    MemberAuthor

    To work around this, edit the generated idempotent migration SQL and change the SELECT to PERFORM. It's a one-time operation that occurs when first changing from SERIAL to IDENTITY, once it's done you shouldn't need to do it again for other migration types.

  5. jhartmann123 commented on Feb 3, 2020

    @jhartmann123
    Contributor

    @roji You mentioned that the issue with PERFORM is reverted in 3.1.1 (#1089 (comment)). However, it's still in there. Looking at the git tree, the revert is only in dev and 3.0.2. Any chance of getting a quick 3.1.2 with the PERFORM issue being reverted?

  6. roji commented on Feb 3, 2020

    @roji
    MemberAuthor

    Shoot, sorry about that - I backported to 3.0 but apparently forgot to backport to 3.1...

    I am releasing 3.1.1.1 with this fix (we try to more or less maintain version sync with EF Core, but they haven't yet released 3.1.2), this should help you all out.

    Note that this kind of bug should no longer occur since we now have real migration tests which actually execute DDL on PostgreSQL. But that's on the 5.0 branch only...

  7. jhartmann123 commented on Feb 3, 2020

    @jhartmann123
    Contributor

    Perfect, everything works fine with 3.1.1.1. Thanks for the quick fix!

  8. YohDeadfall commented on Feb 3, 2020

    @YohDeadfall
    Contributor

    It's still blocked but by dotnet/efcore#14746.

  9. added 2 commits that reference this issue on Aug 29, 2020
    04af9e7
    ab663ab
  10. linked a pull request that will close this issueFix serial to identity in idempotent migrations #1479on Aug 29, 2020
  11. added a commit that references this issue on Aug 31, 2020
    87d46ba
  12. added 2 commits that reference this issue on Aug 31, 2020
    ca7eced
    cf31698
  13. added theissue type on Jun 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions