102 lines
3.6 KiB
C#
102 lines
3.6 KiB
C#
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace BudgetApp.Data.Migrations;
|
|
|
|
/// <inheritdoc />
|
|
public partial class AddSalary : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AddColumn<int>(
|
|
name: "SalaryId",
|
|
table: "Transactions",
|
|
type: "INTEGER",
|
|
nullable: true);
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Salaries",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Name = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
|
|
Amount = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
|
RecurrenceType = table.Column<int>(type: "INTEGER", nullable: false),
|
|
StartDate = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
AccountId = table.Column<int>(type: "INTEGER", nullable: false),
|
|
CategoryId = table.Column<int>(type: "INTEGER", nullable: true),
|
|
UserId = table.Column<string>(type: "TEXT", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Salaries", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Salaries_Accounts_AccountId",
|
|
column: x => x.AccountId,
|
|
principalTable: "Accounts",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_Salaries_AspNetUsers_UserId",
|
|
column: x => x.UserId,
|
|
principalTable: "AspNetUsers",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_Salaries_Categories_CategoryId",
|
|
column: x => x.CategoryId,
|
|
principalTable: "Categories",
|
|
principalColumn: "Id");
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Transactions_SalaryId",
|
|
table: "Transactions",
|
|
column: "SalaryId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Salaries_AccountId",
|
|
table: "Salaries",
|
|
column: "AccountId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Salaries_CategoryId",
|
|
table: "Salaries",
|
|
column: "CategoryId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Salaries_UserId",
|
|
table: "Salaries",
|
|
column: "UserId");
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "FK_Transactions_Salaries_SalaryId",
|
|
table: "Transactions",
|
|
column: "SalaryId",
|
|
principalTable: "Salaries",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropForeignKey(
|
|
name: "FK_Transactions_Salaries_SalaryId",
|
|
table: "Transactions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Salaries");
|
|
|
|
migrationBuilder.DropIndex(
|
|
name: "IX_Transactions_SalaryId",
|
|
table: "Transactions");
|
|
|
|
migrationBuilder.DropColumn(
|
|
name: "SalaryId",
|
|
table: "Transactions");
|
|
}
|
|
} |