using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace Fengling.Member.Infrastructure.Migrations { /// public partial class Init : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "CAPLock", columns: table => new { Key = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), Instance = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), LastLockTime = table.Column(type: "TIMESTAMP", nullable: true) }, constraints: table => { table.PrimaryKey("PK_CAPLock", x => x.Key); }); migrationBuilder.CreateTable( name: "CAPPublishedMessage", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Content = table.Column(type: "TEXT", nullable: true), Retries = table.Column(type: "integer", nullable: true), Added = table.Column(type: "TIMESTAMP", nullable: false), ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), StatusName = table.Column(type: "character varying(40)", maxLength: 40, nullable: false) }, constraints: table => { table.PrimaryKey("PK_CAPPublishedMessage", x => x.Id); }); migrationBuilder.CreateTable( name: "CAPReceivedMessage", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Version = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), Name = table.Column(type: "character varying(400)", maxLength: 400, nullable: false), Group = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), Content = table.Column(type: "TEXT", nullable: true), Retries = table.Column(type: "integer", nullable: true), Added = table.Column(type: "TIMESTAMP", nullable: false), ExpiresAt = table.Column(type: "TIMESTAMP", nullable: true), StatusName = table.Column(type: "character varying(50)", maxLength: 50, nullable: false) }, constraints: table => { table.PrimaryKey("PK_CAPReceivedMessage", x => x.Id); }); migrationBuilder.CreateTable( name: "fls_member", columns: table => new { id = table.Column(type: "uuid", nullable: false, comment: "会员标识"), tenant_id = table.Column(type: "bigint", nullable: false), phone_number = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), open_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), union_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), status = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false), updated_at = table.Column(type: "timestamp with time zone", nullable: true), version = table.Column(type: "integer", nullable: false, defaultValue: 1), Deleted = table.Column(type: "boolean", nullable: false), RowVersion = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_fls_member", x => x.id); }); migrationBuilder.CreateTable( name: "fls_wechat_authorization", columns: table => new { id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), member_id = table.Column(type: "bigint", nullable: false), open_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), union_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), authorized_at = table.Column(type: "timestamp with time zone", nullable: false), last_login_at = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_fls_wechat_authorization", x => x.id); }); migrationBuilder.CreateTable( name: "mka_integraldetails", columns: table => new { id = table.Column(type: "uuid", nullable: false, comment: "积分账户标识"), user_id = table.Column(type: "bigint", nullable: false), tenant_id = table.Column(type: "bigint", nullable: false), points = table.Column(type: "integer", nullable: false, defaultValue: 0), frozen_points = table.Column(type: "integer", nullable: false, defaultValue: 0), version = table.Column(type: "integer", nullable: false, defaultValue: 1), created_at = table.Column(type: "timestamp with time zone", nullable: false), updated_at = table.Column(type: "timestamp with time zone", nullable: true), Deleted = table.Column(type: "boolean", nullable: false), RowVersion = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_mka_integraldetails", x => x.id); }); migrationBuilder.CreateTable( name: "PointsRules", columns: table => new { Id = table.Column(type: "uuid", nullable: false, comment: "规则标识"), Name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false, comment: "规则名称"), Code = table.Column(type: "character varying(50)", maxLength: 50, nullable: false, comment: "规则编码"), RuleType = table.Column(type: "integer", nullable: false, comment: "规则类型"), BasePoints = table.Column(type: "integer", nullable: false, comment: "基础积分"), WeightFactor = table.Column(type: "numeric(18,4)", precision: 18, scale: 4, nullable: true, comment: "权重因子"), ValidityDays = table.Column(type: "integer", nullable: false, comment: "有效期天数"), Priority = table.Column(type: "integer", nullable: false, comment: "优先级"), CalculationMode = table.Column(type: "integer", nullable: false, comment: "计算模式"), IsActive = table.Column(type: "boolean", nullable: false, comment: "是否启用"), EffectiveFrom = table.Column(type: "timestamp with time zone", nullable: false, comment: "生效开始时间"), EffectiveTo = table.Column(type: "timestamp with time zone", nullable: true, comment: "生效结束时间"), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, comment: "创建时间"), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false, comment: "更新时间") }, constraints: table => { table.PrimaryKey("PK_PointsRules", x => x.Id); }); migrationBuilder.CreateTable( name: "fls_member_tag", columns: table => new { id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), member_id = table.Column(type: "uuid", nullable: false), tag_id = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), tag_name = table.Column(type: "character varying(100)", maxLength: 100, nullable: true), created_at = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_fls_member_tag", x => x.id); table.ForeignKey( name: "FK_fls_member_tag_fls_member_member_id", column: x => x.member_id, principalTable: "fls_member", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "OAuthAuthorization", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), MemberId = table.Column(type: "uuid", nullable: false), Provider = table.Column(type: "integer", nullable: false), OpenId = table.Column(type: "text", nullable: false), UnionId = table.Column(type: "text", nullable: true), AccessToken = table.Column(type: "text", nullable: true), RefreshToken = table.Column(type: "text", nullable: true), TokenExpiredAt = table.Column(type: "timestamp with time zone", nullable: true), AuthorizedAt = table.Column(type: "timestamp with time zone", nullable: false), LastLoginAt = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_OAuthAuthorization", x => x.Id); table.ForeignKey( name: "FK_OAuthAuthorization_fls_member_MemberId", column: x => x.MemberId, principalTable: "fls_member", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "PointsTransactions", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), PointsAccountId = table.Column(type: "uuid", nullable: false), MemberId = table.Column(type: "bigint", nullable: false), TenantId = table.Column(type: "bigint", nullable: false), Points = table.Column(type: "integer", nullable: false), TransactionType = table.Column(type: "text", nullable: false), SourceId = table.Column(type: "text", nullable: false), TransactionTypeCategory = table.Column(type: "integer", nullable: false), Remark = table.Column(type: "text", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), ExpireAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PointsTransactions", x => x.Id); table.ForeignKey( name: "FK_PointsTransactions_mka_integraldetails_PointsAccountId", column: x => x.PointsAccountId, principalTable: "mka_integraldetails", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "PointsRuleConditions", columns: table => new { Id = table.Column(type: "uuid", nullable: false, comment: "条件标识"), RuleId = table.Column(type: "uuid", nullable: false, comment: "关联规则标识"), DimensionType = table.Column(type: "integer", nullable: false, comment: "维度类型"), DimensionValue = table.Column(type: "character varying(200)", maxLength: 200, nullable: false, comment: "维度值"), Operator = table.Column(type: "character varying(20)", maxLength: 20, nullable: true, comment: "操作符"), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false, comment: "创建时间") }, constraints: table => { table.PrimaryKey("PK_PointsRuleConditions", x => x.Id); table.ForeignKey( name: "FK_PointsRuleConditions_PointsRules_RuleId", column: x => x.RuleId, principalTable: "PointsRules", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName", table: "CAPPublishedMessage", columns: new[] { "ExpiresAt", "StatusName" }); migrationBuilder.CreateIndex( name: "IX_Version_ExpiresAt_StatusName", table: "CAPPublishedMessage", columns: new[] { "Version", "ExpiresAt", "StatusName" }); migrationBuilder.CreateIndex( name: "IX_ExpiresAt_StatusName1", table: "CAPReceivedMessage", columns: new[] { "ExpiresAt", "StatusName" }); migrationBuilder.CreateIndex( name: "IX_Version_ExpiresAt_StatusName1", table: "CAPReceivedMessage", columns: new[] { "Version", "ExpiresAt", "StatusName" }); migrationBuilder.CreateIndex( name: "idx_member_openid", table: "fls_member", column: "open_id"); migrationBuilder.CreateIndex( name: "idx_member_tenant_phone", table: "fls_member", columns: new[] { "tenant_id", "phone_number" }); migrationBuilder.CreateIndex( name: "idx_member_tenantid", table: "fls_member", column: "tenant_id"); migrationBuilder.CreateIndex( name: "idx_member_unionid", table: "fls_member", column: "union_id"); migrationBuilder.CreateIndex( name: "idx_membertag_member_tag", table: "fls_member_tag", columns: new[] { "member_id", "tag_id" }, unique: true); migrationBuilder.CreateIndex( name: "idx_membertag_tagid", table: "fls_member_tag", column: "tag_id"); migrationBuilder.CreateIndex( name: "idx_wechat_auth_memberid", table: "fls_wechat_authorization", column: "member_id"); migrationBuilder.CreateIndex( name: "idx_wechat_auth_openid", table: "fls_wechat_authorization", column: "open_id", unique: true); migrationBuilder.CreateIndex( name: "idx_wechat_auth_unionid", table: "fls_wechat_authorization", column: "union_id"); migrationBuilder.CreateIndex( name: "idx_points_account_member_tenant", table: "mka_integraldetails", columns: new[] { "user_id", "tenant_id" }); migrationBuilder.CreateIndex( name: "idx_points_account_memberid", table: "mka_integraldetails", column: "user_id", unique: true); migrationBuilder.CreateIndex( name: "IX_OAuthAuthorization_MemberId", table: "OAuthAuthorization", column: "MemberId"); migrationBuilder.CreateIndex( name: "IX_PointsRuleConditions_RuleId_DimensionType", table: "PointsRuleConditions", columns: new[] { "RuleId", "DimensionType" }); migrationBuilder.CreateIndex( name: "IX_PointsRules_Code", table: "PointsRules", column: "Code", unique: true); migrationBuilder.CreateIndex( name: "IX_PointsRules_IsActive", table: "PointsRules", column: "IsActive"); migrationBuilder.CreateIndex( name: "IX_PointsTransactions_PointsAccountId", table: "PointsTransactions", column: "PointsAccountId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "CAPLock"); migrationBuilder.DropTable( name: "CAPPublishedMessage"); migrationBuilder.DropTable( name: "CAPReceivedMessage"); migrationBuilder.DropTable( name: "fls_member_tag"); migrationBuilder.DropTable( name: "fls_wechat_authorization"); migrationBuilder.DropTable( name: "OAuthAuthorization"); migrationBuilder.DropTable( name: "PointsRuleConditions"); migrationBuilder.DropTable( name: "PointsTransactions"); migrationBuilder.DropTable( name: "fls_member"); migrationBuilder.DropTable( name: "PointsRules"); migrationBuilder.DropTable( name: "mka_integraldetails"); } } }