question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Consider redoing extensions, enums, ranges via ModelDiffer

See original GitHub issue

Our current support of PostgreSQL-specific database objects (extensions, enums, ranges, soon hopefully composites) is currently done purely via annotations - objects are represented as metadata on the model, which are then flowed into migrations via annotations on AlterDatabaseOperation. This is unlike EF Core’s support for sequences, for example, which has metadata annotations (like us) but then picks up the sequences in the ModelDiffer, which then generates special {Create,Drop,Rename}SequenceOperation.

Our approach is problematic for the following reasons:

  • Addition/removal of objects needs to be done in our MigrationsSqlGenerator - compare old and new annotations on an AlterDatabaseOperation, calculate what was added, what was removed, etc. This work conceptually belongs in ModelDiffer rather than in MigrationsSqlGenerator.
  • It’s impossible to implement correct DefaultSchema support, because we have no way of knowing that the DefaultSchema has changed, and that our database objects need to be moved accordingly (see https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/pull/685#issuecomment-443488785).

In the past, we already have a discussion about providing our own ModelDiffer, which would generate custom migration operations (e.g. CreateEnumOperation). This would be a better design and align us with the way EF Core does things. It may be worth revisiting for 3.0 in case we change our minds.

/cc @austindrenski @ajcvickers @divega @bricelam

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bricelamcommented, Jan 2, 2019

Oh, and I’m certainly not pushing back on having Npgsql override it (the changes we made in EF Core 2.0 make it safe to do). It’s just something that providers shouldn’t ever have to override so when they do, it’s a good sign we’re missing extensiblity points elsewhere.

1reaction
rojicommented, Dec 10, 2018

OK. I’d recommend not going too far into this without showing an approach we can discuss, to make sure we all agree on where we’re going etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Storing enum-style values in database - int vs. string?
My experience is that enum-style fields are pretty often stored as integers in the database. This means to keep things backward compatible ...
Read more >
What are commonly-used ways to iterate over an enum ...
A pretty common method is to use a static table containing all the enum values, and iterate over that. It's less grimy than...
Read more >
Unsupported REST Use Cases
Use cases currently unsupported when consuming REST services using "enums" and how to overcome some of these situations.
Read more >
Add values to enums through extension
This article explains how to add new values to an enum by extending the enum.
Read more >
Enum classes
Enum constants can declare their own anonymous classes with their corresponding methods, as well as with overriding base methods. enum class ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found