296 lines
14 KiB
C#
296 lines
14 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Apimanager_backend.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitDatabase : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AlterDatabase()
|
|
.Annotation("MySql:CharSet", "utf8mb4");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Apipackages",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "int", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
Name = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
CallLimit = table.Column<int>(type: "int", nullable: false),
|
|
Price = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
|
|
ExpiryDate = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
Username = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Email = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
PassHash = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Role = table.Column<int>(type: "int", nullable: false),
|
|
IsBan = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
IsDelete = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
Balance = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
Name = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Endpoint = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Method = table.Column<int>(type: "int", nullable: false),
|
|
PackageId = table.Column<int>(type: "int", nullable: true),
|
|
IsThirdParty = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
IsActive = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
IsDelete = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
UserId = table.Column<int>(type: "int", nullable: false),
|
|
Operation = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
TargetType = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
TargetId = table.Column<int>(type: "int", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
IpAddress = table.Column<string>(type: "varchar(45)", maxLength: 45, nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
UserAgent = table.Column<string>(type: "longtext", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Description = table.Column<string>(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<int>(type: "int", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
UserId = table.Column<int>(type: "int", nullable: false),
|
|
OrderNumber = table.Column<string>(type: "varchar(255)", nullable: false)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
ThirdPartyOrderId = table.Column<string>(type: "varchar(255)", nullable: true)
|
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
|
Amount = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
|
|
OrderType = table.Column<int>(type: "int", nullable: false),
|
|
Status = table.Column<int>(type: "int", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
Description = table.Column<string>(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<int>(type: "int", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
UserId = table.Column<int>(type: "int", nullable: false),
|
|
PackageId = table.Column<int>(type: "int", nullable: false),
|
|
RemainingCalls = table.Column<int>(type: "int", nullable: false),
|
|
PurchasedAt = table.Column<DateTime>(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<int>(type: "int", nullable: false)
|
|
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
|
UserId = table.Column<int>(type: "int", nullable: false),
|
|
ApiId = table.Column<int>(type: "int", nullable: false),
|
|
CallTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
|
CallResult = table.Column<int>(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);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
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");
|
|
}
|
|
}
|
|
}
|