using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace IBKRTrader.Modules.Accounting.Migrations { /// public partial class InitialAccounting : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AlterDatabase() .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "acc_fx_rates", columns: table => new { Date = table.Column(type: "date", nullable: false), UsdToEur = table.Column(type: "decimal(18,8)", precision: 18, scale: 8, nullable: false), Source = table.Column(type: "varchar(40)", maxLength: 40, nullable: false) .Annotation("MySql:CharSet", "utf8mb4") }, constraints: table => { table.PrimaryKey("PK_acc_fx_rates", x => x.Date); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "acc_ingest_runs", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), AccountId = table.Column(type: "varchar(30)", maxLength: 30, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Backfill = table.Column(type: "tinyint(1)", nullable: false), StartedAt = table.Column(type: "datetime(6)", nullable: false), FinishedAt = table.Column(type: "datetime(6)", nullable: true), FromTimestamp = table.Column(type: "datetime(6)", nullable: true), NewEntries = table.Column(type: "int", nullable: false), DuplicateEntries = table.Column(type: "int", nullable: false), Success = table.Column(type: "tinyint(1)", nullable: false), Message = table.Column(type: "varchar(1000)", maxLength: 1000, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), BalanceAnchorBase = table.Column(type: "decimal(28,8)", precision: 28, scale: 8, nullable: true), LedgerNetBase = table.Column(type: "decimal(28,8)", precision: 28, scale: 8, nullable: true), BalanceDeltaBase = table.Column(type: "decimal(28,8)", precision: 28, scale: 8, nullable: true) }, constraints: table => { table.PrimaryKey("PK_acc_ingest_runs", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "acc_ledger", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), AccountId = table.Column(type: "varchar(30)", maxLength: 30, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), EventType = table.Column(type: "varchar(20)", maxLength: 20, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Timestamp = table.Column(type: "datetime(6)", nullable: false), Symbol = table.Column(type: "varchar(30)", maxLength: 30, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), AssetClass = table.Column(type: "varchar(10)", maxLength: 10, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Currency = table.Column(type: "varchar(5)", maxLength: 5, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Side = table.Column(type: "varchar(10)", maxLength: 10, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Quantity = table.Column(type: "decimal(28,8)", precision: 28, scale: 8, nullable: false), PriceNative = table.Column(type: "decimal(18,6)", precision: 18, scale: 6, nullable: false), GrossBase = table.Column(type: "decimal(28,8)", precision: 28, scale: 8, nullable: false), FeeBase = table.Column(type: "decimal(28,8)", precision: 28, scale: 8, nullable: false), NetBase = table.Column(type: "decimal(28,8)", precision: 28, scale: 8, nullable: false), TransactionId = table.Column(type: "varchar(60)", maxLength: 60, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Source = table.Column(type: "varchar(40)", maxLength: 40, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), IngestBatchId = table.Column(type: "bigint", nullable: false), IngestedAt = table.Column(type: "datetime(6)", nullable: false), IdempotencyKey = table.Column(type: "varchar(120)", maxLength: 120, nullable: false) .Annotation("MySql:CharSet", "utf8mb4") }, constraints: table => { table.PrimaryKey("PK_acc_ledger", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "acc_raw", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), IngestRunId = table.Column(type: "bigint", nullable: false), AccountId = table.Column(type: "varchar(30)", maxLength: 30, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), SourceKind = table.Column(type: "varchar(20)", maxLength: 20, nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), Json = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), CapturedAt = table.Column(type: "datetime(6)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_acc_raw", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_acc_ingest_runs_AccountId_StartedAt", table: "acc_ingest_runs", columns: new[] { "AccountId", "StartedAt" }); migrationBuilder.CreateIndex( name: "IX_acc_ledger_AccountId_Timestamp", table: "acc_ledger", columns: new[] { "AccountId", "Timestamp" }); migrationBuilder.CreateIndex( name: "IX_acc_ledger_EventType", table: "acc_ledger", column: "EventType"); migrationBuilder.CreateIndex( name: "IX_acc_ledger_IdempotencyKey", table: "acc_ledger", column: "IdempotencyKey", unique: true); migrationBuilder.CreateIndex( name: "IX_acc_raw_IngestRunId", table: "acc_raw", column: "IngestRunId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "acc_fx_rates"); migrationBuilder.DropTable( name: "acc_ingest_runs"); migrationBuilder.DropTable( name: "acc_ledger"); migrationBuilder.DropTable( name: "acc_raw"); } } }