using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace AAIntegration.SimmonsBank.API.Migrations { /// public partial class AccountsAllocsOperations : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "CurrencyTypes", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Code = table.Column(type: "text", nullable: false), Symbol = table.Column(type: "text", nullable: false), DecimalPlaces = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CurrencyTypes", x => x.Id); }); migrationBuilder.CreateTable( name: "Accounts", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), OwnerId = table.Column(type: "integer", nullable: false), LastActivity = table.Column(type: "timestamp with time zone", nullable: false), Balance = table.Column(type: "numeric", nullable: false), CreatedOn = table.Column(type: "timestamp with time zone", nullable: false), InitialBalance = table.Column(type: "numeric", nullable: false), CurrencyId = table.Column(type: "integer", nullable: false), ExternalAccountNumber = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Accounts", x => x.Id); table.ForeignKey( name: "FK_Accounts_CurrencyTypes_CurrencyId", column: x => x.CurrencyId, principalTable: "CurrencyTypes", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Accounts_Users_OwnerId", column: x => x.OwnerId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Allocs", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), Enabled = table.Column(type: "boolean", nullable: false), Period = table.Column(type: "interval", nullable: false), AccountId = table.Column(type: "integer", nullable: false), PersistanceEnabled = table.Column(type: "boolean", nullable: false), CurrentBalance = table.Column(type: "numeric", nullable: false), LastTriggeredOn = table.Column(type: "timestamp with time zone", nullable: false), LastBalanceAdded = table.Column(type: "numeric", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Allocs", x => x.Id); table.ForeignKey( name: "FK_Allocs_Accounts_AccountId", column: x => x.AccountId, principalTable: "Accounts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Operations", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Order = table.Column(type: "integer", nullable: false), Enabled = table.Column(type: "boolean", nullable: false), Negative = table.Column(type: "boolean", nullable: false), Mode = table.Column(type: "integer", nullable: false), HistoricPeriod = table.Column(type: "interval", nullable: false), HistoricLookbackDepth = table.Column(type: "integer", nullable: false), HistoricStatistic = table.Column(type: "integer", nullable: false), AbsoluteValue = table.Column(type: "numeric", nullable: false), Percentage = table.Column(type: "numeric", nullable: false), AllocId = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Operations", x => x.Id); table.ForeignKey( name: "FK_Operations_Allocs_AllocId", column: x => x.AllocId, principalTable: "Allocs", principalColumn: "Id"); }); migrationBuilder.CreateIndex( name: "IX_Accounts_CurrencyId", table: "Accounts", column: "CurrencyId"); migrationBuilder.CreateIndex( name: "IX_Accounts_OwnerId", table: "Accounts", column: "OwnerId"); migrationBuilder.CreateIndex( name: "IX_Allocs_AccountId", table: "Allocs", column: "AccountId"); migrationBuilder.CreateIndex( name: "IX_Operations_AllocId", table: "Operations", column: "AllocId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Operations"); migrationBuilder.DropTable( name: "Allocs"); migrationBuilder.DropTable( name: "Accounts"); migrationBuilder.DropTable( name: "CurrencyTypes"); } } }