363 lines
20 KiB
C#
363 lines
20 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Asentrafin.Api.Data.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddPlaidIngestion : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.EnsureSchema(
|
|
name: "app");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "plaid_items",
|
|
schema: "app",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
AccessToken = table.Column<string>(type: "text", nullable: false),
|
|
PlaidItemId = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
InstitutionId = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
InstitutionName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
TransactionsCursor = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
LastAccountsSyncedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
LastTransactionsSyncedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
LastInvestmentsSyncedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_plaid_items", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "plaid_securities",
|
|
schema: "app",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PlaidSecurityId = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
|
Cusip = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
Isin = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
Sedol = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
TickerSymbol = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
Name = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
|
Type = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
ClosePrice = table.Column<decimal>(type: "numeric", nullable: true),
|
|
ClosePriceAsOf = table.Column<DateOnly>(type: "date", nullable: true),
|
|
IsoCurrencyCode = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: true),
|
|
UnofficialCurrencyCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
RawJson = table.Column<string>(type: "jsonb", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_plaid_securities", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "plaid_accounts",
|
|
schema: "app",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PlaidItemId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PlaidAccountId = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
|
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
|
OfficialName = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
|
Mask = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
Type = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
Subtype = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
CurrentBalance = table.Column<decimal>(type: "numeric", nullable: true),
|
|
AvailableBalance = table.Column<decimal>(type: "numeric", nullable: true),
|
|
Limit = table.Column<decimal>(type: "numeric", nullable: true),
|
|
IsoCurrencyCode = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: true),
|
|
UnofficialCurrencyCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
BalanceLastUpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
RawJson = table.Column<string>(type: "jsonb", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_plaid_accounts", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_plaid_accounts_plaid_items_PlaidItemId",
|
|
column: x => x.PlaidItemId,
|
|
principalSchema: "app",
|
|
principalTable: "plaid_items",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "plaid_holdings",
|
|
schema: "app",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PlaidItemId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PlaidAccountId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PlaidSecurityId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Quantity = table.Column<decimal>(type: "numeric", nullable: false),
|
|
InstitutionPrice = table.Column<decimal>(type: "numeric", nullable: true),
|
|
InstitutionValue = table.Column<decimal>(type: "numeric", nullable: true),
|
|
InstitutionPriceAsOf = table.Column<DateOnly>(type: "date", nullable: true),
|
|
CostBasis = table.Column<decimal>(type: "numeric", nullable: true),
|
|
IsoCurrencyCode = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: true),
|
|
UnofficialCurrencyCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
RawJson = table.Column<string>(type: "jsonb", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_plaid_holdings", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_plaid_holdings_plaid_accounts_PlaidAccountId",
|
|
column: x => x.PlaidAccountId,
|
|
principalSchema: "app",
|
|
principalTable: "plaid_accounts",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_plaid_holdings_plaid_items_PlaidItemId",
|
|
column: x => x.PlaidItemId,
|
|
principalSchema: "app",
|
|
principalTable: "plaid_items",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_plaid_holdings_plaid_securities_PlaidSecurityId",
|
|
column: x => x.PlaidSecurityId,
|
|
principalSchema: "app",
|
|
principalTable: "plaid_securities",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "plaid_investment_transactions",
|
|
schema: "app",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PlaidItemId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PlaidAccountId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
PlaidSecurityId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
PlaidInvestmentTransactionId = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
|
AccountPlaidId = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
|
SecurityPlaidId = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
Date = table.Column<DateOnly>(type: "date", nullable: false),
|
|
Name = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
|
|
Quantity = table.Column<decimal>(type: "numeric", nullable: false),
|
|
Amount = table.Column<decimal>(type: "numeric", nullable: false),
|
|
Price = table.Column<decimal>(type: "numeric", nullable: true),
|
|
Fees = table.Column<decimal>(type: "numeric", nullable: true),
|
|
Type = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
Subtype = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
IsoCurrencyCode = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: true),
|
|
UnofficialCurrencyCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
RawJson = table.Column<string>(type: "jsonb", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_plaid_investment_transactions", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_plaid_investment_transactions_plaid_accounts_PlaidAccountId",
|
|
column: x => x.PlaidAccountId,
|
|
principalSchema: "app",
|
|
principalTable: "plaid_accounts",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_plaid_investment_transactions_plaid_items_PlaidItemId",
|
|
column: x => x.PlaidItemId,
|
|
principalSchema: "app",
|
|
principalTable: "plaid_items",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_plaid_investment_transactions_plaid_securities_PlaidSecurit~",
|
|
column: x => x.PlaidSecurityId,
|
|
principalSchema: "app",
|
|
principalTable: "plaid_securities",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "plaid_transactions",
|
|
schema: "app",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PlaidItemId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PlaidAccountId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
PlaidTransactionId = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
|
AccountPlaidId = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
|
Date = table.Column<DateOnly>(type: "date", nullable: false),
|
|
AuthorizedDate = table.Column<DateOnly>(type: "date", nullable: true),
|
|
Name = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: false),
|
|
MerchantName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
Amount = table.Column<decimal>(type: "numeric", nullable: false),
|
|
Pending = table.Column<bool>(type: "boolean", nullable: false),
|
|
IsoCurrencyCode = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: true),
|
|
UnofficialCurrencyCode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
Categories = table.Column<string[]>(type: "text[]", nullable: false),
|
|
PersonalFinanceCategoryPrimary = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
PersonalFinanceCategoryDetailed = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
RemovedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
RawJson = table.Column<string>(type: "jsonb", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_plaid_transactions", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_plaid_transactions_plaid_accounts_PlaidAccountId",
|
|
column: x => x.PlaidAccountId,
|
|
principalSchema: "app",
|
|
principalTable: "plaid_accounts",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_plaid_transactions_plaid_items_PlaidItemId",
|
|
column: x => x.PlaidItemId,
|
|
principalSchema: "app",
|
|
principalTable: "plaid_items",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_accounts_PlaidAccountId",
|
|
schema: "app",
|
|
table: "plaid_accounts",
|
|
column: "PlaidAccountId",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_accounts_PlaidItemId",
|
|
schema: "app",
|
|
table: "plaid_accounts",
|
|
column: "PlaidItemId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_holdings_PlaidAccountId_PlaidSecurityId",
|
|
schema: "app",
|
|
table: "plaid_holdings",
|
|
columns: new[] { "PlaidAccountId", "PlaidSecurityId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_holdings_PlaidItemId",
|
|
schema: "app",
|
|
table: "plaid_holdings",
|
|
column: "PlaidItemId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_holdings_PlaidSecurityId",
|
|
schema: "app",
|
|
table: "plaid_holdings",
|
|
column: "PlaidSecurityId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_investment_transactions_PlaidAccountId",
|
|
schema: "app",
|
|
table: "plaid_investment_transactions",
|
|
column: "PlaidAccountId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_investment_transactions_PlaidInvestmentTransactionId",
|
|
schema: "app",
|
|
table: "plaid_investment_transactions",
|
|
column: "PlaidInvestmentTransactionId",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_investment_transactions_PlaidItemId_Date",
|
|
schema: "app",
|
|
table: "plaid_investment_transactions",
|
|
columns: new[] { "PlaidItemId", "Date" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_investment_transactions_PlaidSecurityId",
|
|
schema: "app",
|
|
table: "plaid_investment_transactions",
|
|
column: "PlaidSecurityId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_items_PlaidItemId",
|
|
schema: "app",
|
|
table: "plaid_items",
|
|
column: "PlaidItemId",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_securities_PlaidSecurityId",
|
|
schema: "app",
|
|
table: "plaid_securities",
|
|
column: "PlaidSecurityId",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_transactions_PlaidAccountId",
|
|
schema: "app",
|
|
table: "plaid_transactions",
|
|
column: "PlaidAccountId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_transactions_PlaidItemId_Date",
|
|
schema: "app",
|
|
table: "plaid_transactions",
|
|
columns: new[] { "PlaidItemId", "Date" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_plaid_transactions_PlaidTransactionId",
|
|
schema: "app",
|
|
table: "plaid_transactions",
|
|
column: "PlaidTransactionId",
|
|
unique: true);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "plaid_holdings",
|
|
schema: "app");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "plaid_investment_transactions",
|
|
schema: "app");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "plaid_transactions",
|
|
schema: "app");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "plaid_securities",
|
|
schema: "app");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "plaid_accounts",
|
|
schema: "app");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "plaid_items",
|
|
schema: "app");
|
|
}
|
|
}
|
|
}
|