using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace YarpGateway.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "ServiceInstances", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ClusterId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), DestinationId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), Address = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Health = table.Column(type: "integer", nullable: false), Weight = table.Column(type: "integer", nullable: false), Status = table.Column(type: "integer", nullable: false), CreatedBy = table.Column(type: "bigint", nullable: true), CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), UpdatedBy = table.Column(type: "bigint", nullable: true), UpdatedTime = table.Column(type: "timestamp with time zone", nullable: true), IsDeleted = table.Column(type: "boolean", nullable: false), Version = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ServiceInstances", x => x.Id); }); migrationBuilder.CreateTable( name: "Tenants", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), TenantCode = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), TenantName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), Status = table.Column(type: "integer", nullable: false), CreatedBy = table.Column(type: "bigint", nullable: true), CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), UpdatedBy = table.Column(type: "bigint", nullable: true), UpdatedTime = table.Column(type: "timestamp with time zone", nullable: true), IsDeleted = table.Column(type: "boolean", nullable: false), Version = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Tenants", x => x.Id); table.UniqueConstraint("AK_Tenants_TenantCode", x => x.TenantCode); }); migrationBuilder.CreateTable( name: "TenantRoutes", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), TenantCode = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), ServiceName = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), ClusterId = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), PathPattern = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Priority = table.Column(type: "integer", nullable: false), Status = table.Column(type: "integer", nullable: false), CreatedBy = table.Column(type: "bigint", nullable: true), CreatedTime = table.Column(type: "timestamp with time zone", nullable: false), UpdatedBy = table.Column(type: "bigint", nullable: true), UpdatedTime = table.Column(type: "timestamp with time zone", nullable: true), IsDeleted = table.Column(type: "boolean", nullable: false), Version = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_TenantRoutes", x => x.Id); table.ForeignKey( name: "FK_TenantRoutes_Tenants_TenantCode", column: x => x.TenantCode, principalTable: "Tenants", principalColumn: "TenantCode", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( name: "IX_ServiceInstances_ClusterId_DestinationId", table: "ServiceInstances", columns: new[] { "ClusterId", "DestinationId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_ServiceInstances_Health", table: "ServiceInstances", column: "Health"); migrationBuilder.CreateIndex( name: "IX_TenantRoutes_ClusterId", table: "TenantRoutes", column: "ClusterId"); migrationBuilder.CreateIndex( name: "IX_TenantRoutes_TenantCode_ServiceName", table: "TenantRoutes", columns: new[] { "TenantCode", "ServiceName" }, unique: true); migrationBuilder.CreateIndex( name: "IX_Tenants_TenantCode", table: "Tenants", column: "TenantCode", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "ServiceInstances"); migrationBuilder.DropTable( name: "TenantRoutes"); migrationBuilder.DropTable( name: "Tenants"); } } }