| 1 | using AgentForge.Data; |
| 2 | using Microsoft.EntityFrameworkCore.Infrastructure; |
| 3 | using Microsoft.EntityFrameworkCore.Migrations; |
| 4 | |
| 5 | #nullable disable |
| 6 | |
| 7 | namespace AgentForge.Data.Migrations |
| 8 | { |
| 9 | [DbContext(typeof(ForgeDbContext))] |
| 10 | [Migration("20260614220000_RepoGroupParentKeyUnique")] |
| 11 | public partial class RepoGroupParentKeyUnique : Migration |
| 12 | { |
| 13 | /// <inheritdoc /> |
| 14 | protected override void Up(MigrationBuilder migrationBuilder) |
| 15 | { |
| 16 | migrationBuilder.AddColumn<string>( |
| 17 | name: "ParentGroupKey", |
| 18 | table: "repo_groups", |
| 19 | type: "TEXT", |
| 20 | nullable: false, |
| 21 | defaultValue: ""); |
| 22 | |
| 23 | migrationBuilder.Sql( |
| 24 | """ |
| 25 | UPDATE repo_groups |
| 26 | SET ParentGroupKey = COALESCE(ParentGroupId, '') |
| 27 | WHERE ParentGroupKey = '' OR ParentGroupKey IS NULL |
| 28 | """); |
| 29 | |
| 30 | migrationBuilder.DropIndex( |
| 31 | name: "IX_repo_groups_OrgId_Slug", |
| 32 | table: "repo_groups"); |
| 33 | |
| 34 | migrationBuilder.DropIndex( |
| 35 | name: "IX_repo_groups_OrgId_ParentGroupId_Slug", |
| 36 | table: "repo_groups"); |
| 37 | |
| 38 | migrationBuilder.CreateIndex( |
| 39 | name: "IX_repo_groups_OrgId_ParentGroupKey_Slug", |
| 40 | table: "repo_groups", |
| 41 | columns: ["OrgId", "ParentGroupKey", "Slug"], |
| 42 | unique: true); |
| 43 | } |
| 44 | |
| 45 | /// <inheritdoc /> |
| 46 | protected override void Down(MigrationBuilder migrationBuilder) |
| 47 | { |
| 48 | migrationBuilder.DropIndex( |
| 49 | name: "IX_repo_groups_OrgId_ParentGroupKey_Slug", |
| 50 | table: "repo_groups"); |
| 51 | |
| 52 | migrationBuilder.CreateIndex( |
| 53 | name: "IX_repo_groups_OrgId_Slug", |
| 54 | table: "repo_groups", |
| 55 | columns: ["OrgId", "Slug"], |
| 56 | unique: true, |
| 57 | filter: "ParentGroupId IS NULL"); |
| 58 | |
| 59 | migrationBuilder.CreateIndex( |
| 60 | name: "IX_repo_groups_OrgId_ParentGroupId_Slug", |
| 61 | table: "repo_groups", |
| 62 | columns: ["OrgId", "ParentGroupId", "Slug"], |
| 63 | unique: true, |
| 64 | filter: "ParentGroupId IS NOT NULL"); |
| 65 | |
| 66 | migrationBuilder.DropColumn( |
| 67 | name: "ParentGroupKey", |
| 68 | table: "repo_groups"); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |