using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace MyOffice.Migrations.Postgres.Migrations { /// public partial class Host : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "CurrencyGlobals", columns: table => new { Id = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: false), ShortName = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CurrencyGlobals", x => x.Id); }); migrationBuilder.CreateTable( name: "Accounts", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CurrencyGlobalId = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Accounts", x => x.Id); table.ForeignKey( name: "FK_Accounts_CurrencyGlobals_CurrencyGlobalId", column: x => x.CurrencyGlobalId, principalTable: "CurrencyGlobals", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Currencies", columns: table => new { Id = table.Column(type: "uuid", nullable: false), CurrencyGlobalId = table.Column(type: "text", nullable: false), UserId = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "text", nullable: false), ShortName = table.Column(type: "text", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Currencies", x => x.Id); table.ForeignKey( name: "FK_Currencies_CurrencyGlobals_CurrencyGlobalId", column: x => x.CurrencyGlobalId, principalTable: "CurrencyGlobals", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Currencies_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AccountAccesses", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), AccountId = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), IsAllowRead = table.Column(type: "boolean", nullable: false), IsAllowWrite = table.Column(type: "boolean", nullable: false), IsAllowManage = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AccountAccesses", x => x.Id); table.ForeignKey( name: "FK_AccountAccesses_Accounts_AccountId", column: x => x.AccountId, principalTable: "Accounts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_AccountAccesses_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "AccountMotions", columns: table => new { Id = table.Column(type: "bigint", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), CreatedOn = table.Column(type: "timestamp with time zone", nullable: false), DateTime = table.Column(type: "timestamp with time zone", nullable: false), AccountId = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), AmountIn = table.Column(type: "numeric", nullable: false), AmountOut = table.Column(type: "numeric", nullable: false) }, constraints: table => { table.PrimaryKey("PK_AccountMotions", x => x.Id); table.ForeignKey( name: "FK_AccountMotions_Accounts_AccountId", column: x => x.AccountId, principalTable: "Accounts", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_AccountMotions_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "CurrencyRates", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), CurrencyId = table.Column(type: "uuid", nullable: false), DateTime = table.Column(type: "timestamp with time zone", nullable: false), Rate = table.Column(type: "numeric", nullable: false) }, constraints: table => { table.PrimaryKey("PK_CurrencyRates", x => x.Id); table.ForeignKey( name: "FK_CurrencyRates_Currencies_CurrencyId", column: x => x.CurrencyId, principalTable: "Currencies", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_AccountAccesses_AccountId", table: "AccountAccesses", column: "AccountId"); migrationBuilder.CreateIndex( name: "IX_AccountAccesses_UserId", table: "AccountAccesses", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_AccountMotions_AccountId", table: "AccountMotions", column: "AccountId"); migrationBuilder.CreateIndex( name: "IX_AccountMotions_UserId", table: "AccountMotions", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Accounts_CurrencyGlobalId", table: "Accounts", column: "CurrencyGlobalId"); migrationBuilder.CreateIndex( name: "IX_Currencies_CurrencyGlobalId", table: "Currencies", column: "CurrencyGlobalId"); migrationBuilder.CreateIndex( name: "IX_Currencies_UserId", table: "Currencies", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_CurrencyRates_CurrencyId", table: "CurrencyRates", column: "CurrencyId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "AccountAccesses"); migrationBuilder.DropTable( name: "AccountMotions"); migrationBuilder.DropTable( name: "CurrencyRates"); migrationBuilder.DropTable( name: "Accounts"); migrationBuilder.DropTable( name: "Currencies"); migrationBuilder.DropTable( name: "CurrencyGlobals"); } } }