using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Asentrafin.Api.Data.Migrations
{
///
public partial class AddTransactionCategorization : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "transaction_categories",
schema: "app",
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
ParentId = table.Column(type: "uuid", nullable: true),
Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false),
Slug = table.Column(type: "character varying(256)", maxLength: 256, nullable: false),
PlaidPrimary = table.Column(type: "character varying(128)", maxLength: 128, nullable: true),
PlaidDetailed = table.Column(type: "character varying(128)", maxLength: 128, nullable: true),
SortOrder = table.Column(type: "integer", nullable: false),
IsSystem = table.Column(type: "boolean", nullable: false),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_transaction_categories", x => x.Id);
table.ForeignKey(
name: "FK_transaction_categories_transaction_categories_ParentId",
column: x => x.ParentId,
principalSchema: "app",
principalTable: "transaction_categories",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "transaction_classifications",
schema: "app",
columns: table => new
{
Id = table.Column(type: "uuid", nullable: false),
PlaidTransactionId = table.Column(type: "uuid", nullable: false),
CategoryId = table.Column(type: "uuid", nullable: false),
Source = table.Column(type: "character varying(64)", maxLength: 64, nullable: false),
Confidence = table.Column(type: "numeric", nullable: true),
Notes = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true),
CreatedAt = table.Column(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_transaction_classifications", x => x.Id);
table.ForeignKey(
name: "FK_transaction_classifications_plaid_transactions_PlaidTransac~",
column: x => x.PlaidTransactionId,
principalSchema: "app",
principalTable: "plaid_transactions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_transaction_classifications_transaction_categories_Category~",
column: x => x.CategoryId,
principalSchema: "app",
principalTable: "transaction_categories",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_transaction_categories_ParentId",
schema: "app",
table: "transaction_categories",
column: "ParentId");
migrationBuilder.CreateIndex(
name: "IX_transaction_categories_PlaidPrimary_PlaidDetailed",
schema: "app",
table: "transaction_categories",
columns: new[] { "PlaidPrimary", "PlaidDetailed" });
migrationBuilder.CreateIndex(
name: "IX_transaction_categories_Slug",
schema: "app",
table: "transaction_categories",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_transaction_classifications_CategoryId",
schema: "app",
table: "transaction_classifications",
column: "CategoryId");
migrationBuilder.CreateIndex(
name: "IX_transaction_classifications_PlaidTransactionId",
schema: "app",
table: "transaction_classifications",
column: "PlaidTransactionId",
unique: true);
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "transaction_classifications",
schema: "app");
migrationBuilder.DropTable(
name: "transaction_categories",
schema: "app");
}
}
}