using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Asentrafin.Api.Data.Migrations
{
///
public partial class AddPlaidIngestion : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "app");
migrationBuilder.CreateTable(
name: "plaid_items",
schema: "app",
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
AccessToken = table.Column(type: "text", nullable: false),
PlaidItemId = table.Column(type: "character varying(128)", maxLength: 128, nullable: true),
InstitutionId = table.Column(type: "character varying(128)", maxLength: 128, nullable: true),
InstitutionName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
TransactionsCursor = table.Column(type: "character varying(512)", maxLength: 512, nullable: true),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false),
LastAccountsSyncedAt = table.Column(type: "timestamp with time zone", nullable: true),
LastTransactionsSyncedAt = table.Column(type: "timestamp with time zone", nullable: true),
LastInvestmentsSyncedAt = table.Column(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(type: "uuid", nullable: false),
PlaidSecurityId = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
Cusip = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
Isin = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
Sedol = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
TickerSymbol = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
Name = table.Column(type: "character varying(512)", maxLength: 512, nullable: true),
Type = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
ClosePrice = table.Column(type: "numeric", nullable: true),
ClosePriceAsOf = table.Column(type: "date", nullable: true),
IsoCurrencyCode = table.Column(type: "character varying(8)", maxLength: 8, nullable: true),
UnofficialCurrencyCode = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false),
RawJson = table.Column(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(type: "uuid", nullable: false),
PlaidItemId = table.Column(type: "uuid", nullable: false),
PlaidAccountId = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false),
OfficialName = table.Column(type: "character varying(512)", maxLength: 512, nullable: true),
Mask = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
Type = table.Column(type: "character varying(64)", maxLength: 64, nullable: false),
Subtype = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
CurrentBalance = table.Column(type: "numeric", nullable: true),
AvailableBalance = table.Column(type: "numeric", nullable: true),
Limit = table.Column(type: "numeric", nullable: true),
IsoCurrencyCode = table.Column(type: "character varying(8)", maxLength: 8, nullable: true),
UnofficialCurrencyCode = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
BalanceLastUpdatedAt = table.Column(type: "timestamp with time zone", nullable: true),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false),
RawJson = table.Column(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(type: "uuid", nullable: false),
PlaidItemId = table.Column(type: "uuid", nullable: false),
PlaidAccountId = table.Column(type: "uuid", nullable: false),
PlaidSecurityId = table.Column(type: "uuid", nullable: false),
Quantity = table.Column(type: "numeric", nullable: false),
InstitutionPrice = table.Column(type: "numeric", nullable: true),
InstitutionValue = table.Column(type: "numeric", nullable: true),
InstitutionPriceAsOf = table.Column(type: "date", nullable: true),
CostBasis = table.Column(type: "numeric", nullable: true),
IsoCurrencyCode = table.Column(type: "character varying(8)", maxLength: 8, nullable: true),
UnofficialCurrencyCode = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false),
RawJson = table.Column(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(type: "uuid", nullable: false),
PlaidItemId = table.Column(type: "uuid", nullable: false),
PlaidAccountId = table.Column(type: "uuid", nullable: true),
PlaidSecurityId = table.Column(type: "uuid", nullable: true),
PlaidInvestmentTransactionId = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
AccountPlaidId = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
SecurityPlaidId = table.Column(type: "character varying(128)", maxLength: 128, nullable: true),
Date = table.Column(type: "date", nullable: false),
Name = table.Column(type: "character varying(512)", maxLength: 512, nullable: false),
Quantity = table.Column(type: "numeric", nullable: false),
Amount = table.Column(type: "numeric", nullable: false),
Price = table.Column(type: "numeric", nullable: true),
Fees = table.Column(type: "numeric", nullable: true),
Type = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
Subtype = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
IsoCurrencyCode = table.Column(type: "character varying(8)", maxLength: 8, nullable: true),
UnofficialCurrencyCode = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false),
RawJson = table.Column(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(type: "uuid", nullable: false),
PlaidItemId = table.Column(type: "uuid", nullable: false),
PlaidAccountId = table.Column(type: "uuid", nullable: true),
PlaidTransactionId = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
AccountPlaidId = table.Column(type: "character varying(128)", maxLength: 128, nullable: false),
Date = table.Column(type: "date", nullable: false),
AuthorizedDate = table.Column(type: "date", nullable: true),
Name = table.Column(type: "character varying(512)", maxLength: 512, nullable: false),
MerchantName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
Amount = table.Column(type: "numeric", nullable: false),
Pending = table.Column(type: "boolean", nullable: false),
IsoCurrencyCode = table.Column(type: "character varying(8)", maxLength: 8, nullable: true),
UnofficialCurrencyCode = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
Categories = table.Column(type: "text[]", nullable: false),
PersonalFinanceCategoryPrimary = table.Column(type: "character varying(128)", maxLength: 128, nullable: true),
PersonalFinanceCategoryDetailed = table.Column(type: "character varying(128)", maxLength: 128, nullable: true),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false),
RemovedAt = table.Column(type: "timestamp with time zone", nullable: true),
RawJson = table.Column(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);
}
///
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");
}
}
}