classlib/ExpenseTracker.Persistence/PostgreSQL/Migrations/20240408161520_Add_Budgets_and_Expenses_relations.cs
2024-08-07 21:12:02 +03:00

81 lines
3.3 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ExpenseTracker.Persistence.PostgreSQL.Migrations
{
/// <inheritdoc />
public partial class Add_Budgets_and_Expenses_relations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "domain");
migrationBuilder.CreateTable(
name: "budgets",
schema: "domain",
columns: table => new
{
id = table.Column<string>(type: "text", nullable: false),
amount = table.Column<double>(type: "double precision", nullable: false),
currency = table.Column<string>(type: "text", nullable: false),
category = table.Column<string>(type: "text", nullable: false),
from_time = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
to_time = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
fk_budget_user_id = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_budgets", x => x.id);
});
migrationBuilder.CreateTable(
name: "expenses",
schema: "domain",
columns: table => new
{
id = table.Column<string>(type: "text", nullable: false),
amount = table.Column<double>(type: "double precision", nullable: false),
currency = table.Column<string>(type: "text", nullable: false),
category = table.Column<string>(type: "text", nullable: false),
time = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
description = table.Column<string>(type: "text", nullable: false),
BudgetId = table.Column<string>(type: "text", nullable: true),
fk_expense_user_id = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_expenses", x => x.id);
table.ForeignKey(
name: "fk_expense_budget_id",
column: x => x.BudgetId,
principalSchema: "domain",
principalTable: "budgets",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_expenses_BudgetId",
schema: "domain",
table: "expenses",
column: "BudgetId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "expenses",
schema: "domain");
migrationBuilder.DropTable(
name: "budgets",
schema: "domain");
}
}
}