Efcore.pg: Can't change from SERIAL to IDENTITY columns in idempotent migrations

Created on 9 Dec 2019  路  6Comments  路  Source: npgsql/efcore.pg

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 (https://github.com/aspnet/EntityFrameworkCore/issues/19250).

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

bug

Most helpful comment

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

All 6 comments

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.

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.

@roji You mentioned that the issue with PERFORM is reverted in 3.1.1 (https://github.com/npgsql/efcore.pg/issues/1089#issuecomment-563227122). 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?

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

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

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

Was this page helpful?
0 / 5 - 0 ratings