using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ExpenseTracker.Persistence.PostgreSQL.Migrations
{
///
public partial class Add_Budgets_and_Expenses_relations : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "domain");
migrationBuilder.CreateTable(
name: "budgets",
schema: "domain",
columns: table => new
{
id = table.Column(type: "text", nullable: false),
amount = table.Column(type: "double precision", nullable: false),
currency = table.Column(type: "text", nullable: false),
category = table.Column(type: "text", nullable: false),
from_time = table.Column(type: "timestamp with time zone", nullable: false),
to_time = table.Column(type: "timestamp with time zone", nullable: false),
fk_budget_user_id = table.Column(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(type: "text", nullable: false),
amount = table.Column(type: "double precision", nullable: false),
currency = table.Column(type: "text", nullable: false),
category = table.Column(type: "text", nullable: false),
time = table.Column(type: "timestamp with time zone", nullable: false),
description = table.Column(type: "text", nullable: false),
BudgetId = table.Column(type: "text", nullable: true),
fk_expense_user_id = table.Column(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");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "expenses",
schema: "domain");
migrationBuilder.DropTable(
name: "budgets",
schema: "domain");
}
}
}