using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace FinlyticEngine.Migrations { /// public partial class InitialEngineMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "DynamicSettings", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Key = table.Column(type: "character varying(150)", maxLength: 150, nullable: false), ValueJson = table.Column(type: "text", nullable: false), ServiceIdentifier = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), LastUpdatedUtc = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_DynamicSettings", x => x.Id); }); migrationBuilder.CreateTable( name: "engine_evaluation_snapshots", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Isin = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), Symbol = table.Column(type: "character varying(30)", maxLength: 30, nullable: false), TechnicalScore = table.Column(type: "numeric(6,2)", nullable: false), SentimentScore = table.Column(type: "numeric(6,2)", nullable: false), FundamentalScore = table.Column(type: "numeric(6,2)", nullable: false), CompositeOpportunityScore = table.Column(type: "numeric(6,2)", nullable: false), PassedEarningsLockout = table.Column(type: "boolean", nullable: false), DaysToNextEarnings = table.Column(type: "integer", nullable: true), PassedAiValidation = table.Column(type: "boolean", nullable: false), AiThesisSummary = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: false), EvaluatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_engine_evaluation_snapshots", x => x.Id); }); migrationBuilder.CreateTable( name: "engine_trade_proposals", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UnderlyingIsin = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), Symbol = table.Column(type: "character varying(30)", maxLength: 30, nullable: false), StrategyKey = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), Direction = table.Column(type: "integer", nullable: false), QualityScore = table.Column(type: "numeric(6,2)", nullable: false), CompositeScore = table.Column(type: "numeric(6,2)", nullable: false), CurrentPrice = table.Column(type: "numeric(18,4)", nullable: false), EntryPrice = table.Column(type: "numeric(18,4)", nullable: false), StopLoss = table.Column(type: "numeric(18,4)", nullable: false), TakeProfit1 = table.Column(type: "numeric(18,4)", nullable: false), RiskRewardRatio = table.Column(type: "numeric(8,2)", nullable: false), ExitPlan = table.Column(type: "jsonb", nullable: false), SelectedDerivative = table.Column(type: "jsonb", nullable: true), AiValidation = table.Column(type: "jsonb", nullable: false), IsActive = table.Column(type: "boolean", nullable: false), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), ExpiresAtUtc = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_engine_trade_proposals", x => x.Id); }); migrationBuilder.CreateTable( name: "engine_trades", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ProposalId = table.Column(type: "uuid", nullable: false), UnderlyingIsin = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), Symbol = table.Column(type: "character varying(30)", maxLength: 30, nullable: false), DerivativeIsin = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), DerivativeWkn = table.Column(type: "character varying(20)", maxLength: 20, nullable: true), ExecutionMode = table.Column(type: "integer", nullable: false), InstrumentType = table.Column(type: "integer", nullable: false), Direction = table.Column(type: "integer", nullable: false), Status = table.Column(type: "integer", nullable: false), AverageBuyIn = table.Column(type: "numeric(18,4)", nullable: false), TotalQuantity = table.Column(type: "numeric(18,4)", nullable: false), InitialStopLoss = table.Column(type: "numeric(18,4)", nullable: false), CurrentStopLoss = table.Column(type: "numeric(18,4)", nullable: false), CurrentPrice = table.Column(type: "numeric(18,4)", nullable: false), TakeProfit1 = table.Column(type: "numeric(18,4)", nullable: false), TakeProfit2 = table.Column(type: "numeric(18,4)", nullable: false), TakeProfitRunner = table.Column(type: "numeric(18,4)", nullable: true), RealizedPnlEur = table.Column(type: "numeric(18,4)", nullable: false), TotalFeesEur = table.Column(type: "numeric(18,4)", nullable: false), ExitPlan = table.Column(type: "jsonb", nullable: false), ScoreBreakdownJson = table.Column(type: "text", nullable: false), OpenedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), ClosedAtUtc = table.Column(type: "timestamp with time zone", nullable: true), LastUpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_engine_trades", x => x.Id); }); migrationBuilder.CreateTable( name: "engine_trade_fills", columns: table => new { Id = table.Column(type: "uuid", nullable: false), TradeId = table.Column(type: "uuid", nullable: false), ExecutedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), Price = table.Column(type: "numeric(18,4)", nullable: false), Quantity = table.Column(type: "numeric(18,4)", nullable: false), Fee = table.Column(type: "numeric(18,4)", nullable: false), Note = table.Column(type: "character varying(500)", maxLength: 500, nullable: true) }, constraints: table => { table.PrimaryKey("PK_engine_trade_fills", x => x.Id); table.ForeignKey( name: "FK_engine_trade_fills_engine_trades_TradeId", column: x => x.TradeId, principalTable: "engine_trades", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_DynamicSettings_Key", table: "DynamicSettings", column: "Key", unique: true); migrationBuilder.CreateIndex( name: "IX_engine_evaluation_snapshots_CompositeOpportunityScore", table: "engine_evaluation_snapshots", column: "CompositeOpportunityScore"); migrationBuilder.CreateIndex( name: "IX_engine_evaluation_snapshots_Isin_EvaluatedAtUtc", table: "engine_evaluation_snapshots", columns: new[] { "Isin", "EvaluatedAtUtc" }); migrationBuilder.CreateIndex( name: "IX_engine_trade_fills_TradeId_ExecutedAtUtc", table: "engine_trade_fills", columns: new[] { "TradeId", "ExecutedAtUtc" }); migrationBuilder.CreateIndex( name: "IX_engine_trade_proposals_CompositeScore", table: "engine_trade_proposals", column: "CompositeScore"); migrationBuilder.CreateIndex( name: "IX_engine_trade_proposals_CreatedAtUtc", table: "engine_trade_proposals", column: "CreatedAtUtc"); migrationBuilder.CreateIndex( name: "IX_engine_trade_proposals_UnderlyingIsin_IsActive_ExpiresAtUtc", table: "engine_trade_proposals", columns: new[] { "UnderlyingIsin", "IsActive", "ExpiresAtUtc" }); migrationBuilder.CreateIndex( name: "IX_engine_trades_OpenedAtUtc", table: "engine_trades", column: "OpenedAtUtc"); migrationBuilder.CreateIndex( name: "IX_engine_trades_Status_UnderlyingIsin", table: "engine_trades", columns: new[] { "Status", "UnderlyingIsin" }); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "DynamicSettings"); migrationBuilder.DropTable( name: "engine_evaluation_snapshots"); migrationBuilder.DropTable( name: "engine_trade_fills"); migrationBuilder.DropTable( name: "engine_trade_proposals"); migrationBuilder.DropTable( name: "engine_trades"); } } }