using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Apimanager_backend.Migrations { /// public partial class InitDatabase : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterDatabase() .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Apipackages", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(type: "varchar(20)", maxLength: 20, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), CallLimit = table.Column(type: "int", nullable: false), Price = table.Column(type: "decimal(65,30)", nullable: false), ExpiryDate = table.Column(type: "datetime(6)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Apipackages", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Username = table.Column(type: "varchar(255)", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Email = table.Column(type: "varchar(255)", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), PassHash = table.Column(type: "varchar(255)", maxLength: 255, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Role = table.Column(type: "int", nullable: false), IsBan = table.Column(type: "tinyint(1)", nullable: false), IsDelete = table.Column(type: "tinyint(1)", nullable: false), Balance = table.Column(type: "decimal(65,30)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Apis", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), Name = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Endpoint = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Method = table.Column(type: "int", nullable: false), PackageId = table.Column(type: "int", nullable: true), IsThirdParty = table.Column(type: "tinyint(1)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false), IsDelete = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Apis", x => x.Id); table.ForeignKey( name: "FK_Apis_Apipackages_PackageId", column: x => x.PackageId, principalTable: "Apipackages", principalColumn: "Id"); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "OperationLogs", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), UserId = table.Column(type: "int", nullable: false), Operation = table.Column(type: "varchar(20)", maxLength: 20, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), TargetType = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), TargetId = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IpAddress = table.Column(type: "varchar(45)", maxLength: 45, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), UserAgent = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Description = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4") }, constraints: table => { table.PrimaryKey("PK_OperationLogs", x => x.Id); table.ForeignKey( name: "FK_OperationLogs_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "Orders", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), UserId = table.Column(type: "int", nullable: false), OrderNumber = table.Column(type: "varchar(255)", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), ThirdPartyOrderId = table.Column(type: "varchar(255)", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), Amount = table.Column(type: "decimal(65,30)", nullable: false), OrderType = table.Column(type: "int", nullable: false), Status = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), UpdatedAt = table.Column(type: "datetime(6)", nullable: false), Description = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4") }, constraints: table => { table.PrimaryKey("PK_Orders", x => x.Id); table.ForeignKey( name: "FK_Orders_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "UserPackages", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), UserId = table.Column(type: "int", nullable: false), PackageId = table.Column(type: "int", nullable: false), RemainingCalls = table.Column(type: "int", nullable: false), PurchasedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserPackages", x => x.Id); table.ForeignKey( name: "FK_UserPackages_Apipackages_PackageId", column: x => x.PackageId, principalTable: "Apipackages", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserPackages_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "CallLogs", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), UserId = table.Column(type: "int", nullable: false), ApiId = table.Column(type: "int", nullable: false), CallTime = table.Column(type: "datetime(6)", nullable: false), CallResult = table.Column(type: "int", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CallLogs", x => x.Id); table.ForeignKey( name: "FK_CallLogs_Apis_ApiId", column: x => x.ApiId, principalTable: "Apis", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_CallLogs_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_Apis_PackageId", table: "Apis", column: "PackageId"); migrationBuilder.CreateIndex( name: "IX_CallLogs_ApiId", table: "CallLogs", column: "ApiId"); migrationBuilder.CreateIndex( name: "IX_CallLogs_UserId", table: "CallLogs", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_OperationLogs_UserId", table: "OperationLogs", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Orders_OrderNumber", table: "Orders", column: "OrderNumber", unique: true); migrationBuilder.CreateIndex( name: "IX_Orders_ThirdPartyOrderId", table: "Orders", column: "ThirdPartyOrderId", unique: true); migrationBuilder.CreateIndex( name: "IX_Orders_UserId", table: "Orders", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_UserPackages_PackageId", table: "UserPackages", column: "PackageId"); migrationBuilder.CreateIndex( name: "IX_UserPackages_UserId", table: "UserPackages", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Users_Email", table: "Users", column: "Email", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_Username", table: "Users", column: "Username", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "CallLogs"); migrationBuilder.DropTable( name: "OperationLogs"); migrationBuilder.DropTable( name: "Orders"); migrationBuilder.DropTable( name: "UserPackages"); migrationBuilder.DropTable( name: "Apis"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Apipackages"); } } }