121 lines
5.6 KiB
C#
121 lines
5.6 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Asentrafin.Api.Data.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class AddTransactionCategorization : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "transaction_categories",
|
|
schema: "app",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
ParentId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
|
Slug = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
|
PlaidPrimary = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
PlaidDetailed = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
SortOrder = table.Column<int>(type: "integer", nullable: false),
|
|
IsSystem = table.Column<bool>(type: "boolean", nullable: false),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false),
|
|
PlaidTransactionId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
CategoryId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Source = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
|
Confidence = table.Column<decimal>(type: "numeric", nullable: true),
|
|
Notes = table.Column<string>(type: "character varying(1024)", maxLength: 1024, nullable: true),
|
|
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTimeOffset>(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);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "transaction_classifications",
|
|
schema: "app");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "transaction_categories",
|
|
schema: "app");
|
|
}
|
|
}
|
|
}
|