-
Notifications
You must be signed in to change notification settings - Fork 0
T2(customer): add EF Core persistence with ORM config and initial migration #62
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
Open
devin-ai-integration
wants to merge
1
commit into
devin/customer-service-t1
Choose a base branch
from
devin/customer-service-t2
base: devin/customer-service-t1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...Customer/Customer.Infrastructure/Data/Migrations/20260626044302_InitialCreate.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
...Services/Customer/Customer.Infrastructure/Data/Migrations/20260626044302_InitialCreate.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| using System; | ||
| using Microsoft.EntityFrameworkCore.Migrations; | ||
| using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; | ||
|
|
||
| #nullable disable | ||
|
|
||
| namespace Customer.Infrastructure.Data.Migrations | ||
| { | ||
| /// <inheritdoc /> | ||
| public partial class InitialCreate : Migration | ||
| { | ||
| /// <inheritdoc /> | ||
| protected override void Up(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.CreateTable( | ||
| name: "AppCustomers", | ||
| columns: table => new | ||
| { | ||
| Id = table.Column<int>(type: "integer", nullable: false) | ||
| .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), | ||
| Name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false), | ||
| Email = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false), | ||
| PhoneNumber = table.Column<string>(type: "character varying(30)", unicode: false, maxLength: 30, nullable: true), | ||
| Address = table.Column<string>(type: "text", nullable: true), | ||
| City = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true), | ||
| Gender = table.Column<int>(type: "integer", nullable: false), | ||
| CreatedBy = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true), | ||
| UpdatedBy = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: true), | ||
| CreatedDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false), | ||
| UpdatedDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false) | ||
| }, | ||
| constraints: table => | ||
| { | ||
| table.PrimaryKey("PK_AppCustomers", x => x.Id); | ||
| }); | ||
|
|
||
| migrationBuilder.CreateIndex( | ||
| name: "IX_AppCustomers_Name", | ||
| table: "AppCustomers", | ||
| column: "Name"); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| protected override void Down(MigrationBuilder migrationBuilder) | ||
| { | ||
| migrationBuilder.DropTable( | ||
| name: "AppCustomers"); | ||
| } | ||
| } | ||
| } |
81 changes: 81 additions & 0 deletions
81
...rvices/Customer/Customer.Infrastructure/Data/Migrations/CustomerDbContextModelSnapshot.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // <auto-generated /> | ||
| using System; | ||
| using Customer.Infrastructure.Data; | ||
| using Microsoft.EntityFrameworkCore; | ||
| using Microsoft.EntityFrameworkCore.Infrastructure; | ||
| using Microsoft.EntityFrameworkCore.Storage.ValueConversion; | ||
| using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; | ||
|
|
||
| #nullable disable | ||
|
|
||
| namespace Customer.Infrastructure.Data.Migrations | ||
| { | ||
| [DbContext(typeof(CustomerDbContext))] | ||
| partial class CustomerDbContextModelSnapshot : ModelSnapshot | ||
| { | ||
| protected override void BuildModel(ModelBuilder modelBuilder) | ||
| { | ||
| #pragma warning disable 612, 618 | ||
| modelBuilder | ||
| .HasAnnotation("ProductVersion", "10.0.9") | ||
| .HasAnnotation("Relational:MaxIdentifierLength", 63); | ||
|
|
||
| NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); | ||
|
|
||
| modelBuilder.Entity("Customer.Domain.Entities.Customer", b => | ||
| { | ||
| b.Property<int>("Id") | ||
| .ValueGeneratedOnAdd() | ||
| .HasColumnType("integer"); | ||
|
|
||
| NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); | ||
|
|
||
| b.Property<string>("Address") | ||
| .HasColumnType("text"); | ||
|
|
||
| b.Property<string>("City") | ||
| .HasMaxLength(50) | ||
| .HasColumnType("character varying(50)"); | ||
|
|
||
| b.Property<string>("CreatedBy") | ||
| .HasMaxLength(40) | ||
| .HasColumnType("character varying(40)"); | ||
|
|
||
| b.Property<DateTime>("CreatedDate") | ||
| .HasColumnType("timestamp with time zone"); | ||
|
|
||
| b.Property<string>("Email") | ||
| .IsRequired() | ||
| .HasMaxLength(100) | ||
| .HasColumnType("character varying(100)"); | ||
|
|
||
| b.Property<int>("Gender") | ||
| .HasColumnType("integer"); | ||
|
|
||
| b.Property<string>("Name") | ||
| .IsRequired() | ||
| .HasMaxLength(100) | ||
| .HasColumnType("character varying(100)"); | ||
|
|
||
| b.Property<string>("PhoneNumber") | ||
| .HasMaxLength(30) | ||
| .IsUnicode(false) | ||
| .HasColumnType("character varying(30)"); | ||
|
|
||
| b.Property<string>("UpdatedBy") | ||
| .HasMaxLength(40) | ||
| .HasColumnType("character varying(40)"); | ||
|
|
||
| b.Property<DateTime>("UpdatedDate") | ||
| .HasColumnType("timestamp with time zone"); | ||
|
|
||
| b.HasKey("Id"); | ||
|
|
||
| b.HasIndex("Name"); | ||
|
|
||
| b.ToTable("AppCustomers", (string)null); | ||
| }); | ||
| #pragma warning restore 612, 618 | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Database setup method conflicts with migrations, making future schema updates fail
The database is created using a shortcut method (
EnsureCreated()atsrc/Services/Customer/Customer.API/Program.cs:19) instead of applying the migrations that the PR also introduces, so the migration history table is never populated and any future migration will crash because the tables already exist.Impact: After the first startup, all subsequent schema migrations will fail with "table already exists" errors, making the migration files in this PR useless.
EnsureCreated vs Migrate conflict mechanism
db.Database.EnsureCreated()creates the schema directly without recording anything in the__EFMigrationsHistorytable. The PR also adds a full EF Core migration (src/Services/Customer/Customer.Infrastructure/Data/Migrations/20260626044302_InitialCreate.cs) which expects to be tracked in that history table.When a developer later adds a second migration and runs
db.Database.Migrate()ordotnet ef database update, EF Core will see no migration history and attempt to applyInitialCreate, which will fail because theAppCustomerstable already exists.The RECON.md at
src/Services/Customer/RECON.md:115states the T2 validation gate requires: "EF migration applies against PostgreSQL" — this cannot work withEnsureCreated().The fix is to replace
db.Database.EnsureCreated()withdb.Database.Migrate()so the migration is applied and tracked properly.Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid point about
EnsureCreated()vsMigrate()for long-term migration tracking. However, this follows the existing pattern used by the Notification service (Notification.API/Program.cs:26) and was explicitly requested in the task spec. Deferring to the task author on whether to switch toMigrate()in a follow-up.