Files
luminous-sales/LuminousSales/Models/Migrations/20210317183331_InitialMigration.cs
2021-03-17 22:02:52 +02:00

230 lines
8.4 KiB
C#

using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Data.Migrations
{
public partial class InitialMigration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Permission",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Permission", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Role",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Role", x => x.Id);
});
migrationBuilder.CreateTable(
name: "RolePermission",
columns: table => new
{
RoleId = table.Column<int>(nullable: false),
PermisionId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RolePermission", x => new { x.RoleId, x.PermisionId });
table.ForeignKey(
name: "FK_RolePermission_Permission_PermisionId",
column: x => x.PermisionId,
principalTable: "Permission",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RolePermission_Role_RoleId",
column: x => x.RoleId,
principalTable: "Role",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "User",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: false),
Password = table.Column<string>(nullable: false),
RoleId = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_User", x => x.Id);
table.ForeignKey(
name: "FK_User_Role_RoleId",
column: x => x.RoleId,
principalTable: "Role",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Deal",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(nullable: false),
Time = table.Column<byte[]>(rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Deal", x => x.Id);
table.ForeignKey(
name: "FK_Deal_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Stock",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<int>(nullable: false),
Time = table.Column<byte[]>(rowVersion: true, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Stock", x => x.Id);
table.ForeignKey(
name: "FK_Stock_User_UserId",
column: x => x.UserId,
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Product",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(nullable: false),
Price = table.Column<double>(nullable: false),
AmountInStock = table.Column<double>(nullable: false),
DealId = table.Column<int>(nullable: true),
StockId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Product", x => x.Id);
table.ForeignKey(
name: "FK_Product_Deal_DealId",
column: x => x.DealId,
principalTable: "Deal",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "FK_Product_Stock_StockId",
column: x => x.StockId,
principalTable: "Stock",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_Deal_UserId",
table: "Deal",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Permission_Name",
table: "Permission",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Product_DealId",
table: "Product",
column: "DealId");
migrationBuilder.CreateIndex(
name: "IX_Product_Name",
table: "Product",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Product_StockId",
table: "Product",
column: "StockId");
migrationBuilder.CreateIndex(
name: "IX_Role_Name",
table: "Role",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_RolePermission_PermisionId",
table: "RolePermission",
column: "PermisionId");
migrationBuilder.CreateIndex(
name: "IX_Stock_UserId",
table: "Stock",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_User_RoleId",
table: "User",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "IX_User_Name_Password",
table: "User",
columns: new[] { "Name", "Password" },
unique: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Product");
migrationBuilder.DropTable(
name: "RolePermission");
migrationBuilder.DropTable(
name: "Deal");
migrationBuilder.DropTable(
name: "Stock");
migrationBuilder.DropTable(
name: "Permission");
migrationBuilder.DropTable(
name: "User");
migrationBuilder.DropTable(
name: "Role");
}
}
}