PhoneToolMX/PhoneToolMX.Models/Migrations/20231015015926_InitialCreate.cs

289 lines
13 KiB
C#
Raw Normal View History

2023-10-18 04:55:10 +00:00
using System;
using System.Net.NetworkInformation;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace PhoneToolMX.Models.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "PhoneModels",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ModelName = table.Column<string>(type: "text", nullable: true),
MaxExtensions = table.Column<long>(type: "bigint", nullable: false),
PreVvxPolycom = table.Column<bool>(type: "boolean", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PhoneModels", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Role",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: true),
NormalizedName = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Role", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
UserName = table.Column<string>(type: "text", nullable: true),
NormalizedUserName = table.Column<string>(type: "text", nullable: true),
Email = table.Column<string>(type: "text", nullable: true),
NormalizedEmail = table.Column<string>(type: "text", nullable: true),
EmailConfirmed = table.Column<bool>(type: "boolean", nullable: false),
PasswordHash = table.Column<string>(type: "text", nullable: true),
SecurityStamp = table.Column<string>(type: "text", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true),
PhoneNumber = table.Column<string>(type: "text", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "boolean", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "boolean", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
LockoutEnabled = table.Column<bool>(type: "boolean", nullable: false),
AccessFailedCount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "CustomData",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FriendlyName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: true),
DataType = table.Column<int>(type: "integer", nullable: false),
Size = table.Column<long>(type: "bigint", nullable: false),
Data = table.Column<byte[]>(type: "bytea", nullable: true),
PhoneId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_CustomData", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Extensions",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ExtId = table.Column<int>(type: "integer", nullable: false, computedColumnSql: "\"Id\" + 1000", stored: true),
DirectoryName = table.Column<string>(type: "text", nullable: false),
Listed = table.Column<bool>(type: "boolean", nullable: false),
HoldMusicId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Extensions", x => x.Id);
table.ForeignKey(
name: "FK_Extensions_CustomData_HoldMusicId",
column: x => x.HoldMusicId,
principalTable: "CustomData",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Phones",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
MacAddress = table.Column<PhysicalAddress>(type: "macaddr", nullable: false),
FriendlyName = table.Column<string>(type: "text", nullable: false),
ModelId = table.Column<int>(type: "integer", nullable: false),
BackgroundId = table.Column<int>(type: "integer", nullable: true),
Password = table.Column<string>(type: "text", nullable: true, defaultValueSql: "encode(gen_random_bytes(18), 'base64')")
},
constraints: table =>
{
table.PrimaryKey("PK_Phones", x => x.Id);
table.ForeignKey(
name: "FK_Phones_CustomData_BackgroundId",
column: x => x.BackgroundId,
principalTable: "CustomData",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Phones_PhoneModels_ModelId",
column: x => x.ModelId,
principalTable: "PhoneModels",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ExtensionUser",
columns: table => new
{
ExtensionsId = table.Column<int>(type: "integer", nullable: false),
OwnersId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ExtensionUser", x => new { x.ExtensionsId, x.OwnersId });
table.ForeignKey(
name: "FK_ExtensionUser_Extensions_ExtensionsId",
column: x => x.ExtensionsId,
principalTable: "Extensions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ExtensionUser_Users_OwnersId",
column: x => x.OwnersId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ExtensionPhone",
columns: table => new
{
ExtensionsId = table.Column<int>(type: "integer", nullable: false),
PhonesId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ExtensionPhone", x => new { x.ExtensionsId, x.PhonesId });
table.ForeignKey(
name: "FK_ExtensionPhone_Extensions_ExtensionsId",
column: x => x.ExtensionsId,
principalTable: "Extensions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ExtensionPhone_Phones_PhonesId",
column: x => x.PhonesId,
principalTable: "Phones",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "PhoneUser",
columns: table => new
{
OwnersId = table.Column<string>(type: "text", nullable: false),
PhonesId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PhoneUser", x => new { x.OwnersId, x.PhonesId });
table.ForeignKey(
name: "FK_PhoneUser_Phones_PhonesId",
column: x => x.PhonesId,
principalTable: "Phones",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_PhoneUser_Users_OwnersId",
column: x => x.OwnersId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "PhoneModels",
columns: new[] { "Id", "MaxExtensions", "ModelName", "PreVvxPolycom" },
values: new object[] { 0, 6L, "Polycom VVX300/310", false });
migrationBuilder.CreateIndex(
name: "IX_CustomData_PhoneId",
table: "CustomData",
column: "PhoneId");
migrationBuilder.CreateIndex(
name: "IX_ExtensionPhone_PhonesId",
table: "ExtensionPhone",
column: "PhonesId");
migrationBuilder.CreateIndex(
name: "IX_Extensions_HoldMusicId",
table: "Extensions",
column: "HoldMusicId");
migrationBuilder.CreateIndex(
name: "IX_ExtensionUser_OwnersId",
table: "ExtensionUser",
column: "OwnersId");
migrationBuilder.CreateIndex(
name: "IX_Phones_BackgroundId",
table: "Phones",
column: "BackgroundId");
migrationBuilder.CreateIndex(
name: "IX_Phones_ModelId",
table: "Phones",
column: "ModelId");
migrationBuilder.CreateIndex(
name: "IX_PhoneUser_PhonesId",
table: "PhoneUser",
column: "PhonesId");
migrationBuilder.AddForeignKey(
name: "FK_CustomData_Phones_PhoneId",
table: "CustomData",
column: "PhoneId",
principalTable: "Phones",
principalColumn: "Id");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_CustomData_Phones_PhoneId",
table: "CustomData");
migrationBuilder.DropTable(
name: "ExtensionPhone");
migrationBuilder.DropTable(
name: "ExtensionUser");
migrationBuilder.DropTable(
name: "PhoneUser");
migrationBuilder.DropTable(
name: "Role");
migrationBuilder.DropTable(
name: "Extensions");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Phones");
migrationBuilder.DropTable(
name: "CustomData");
migrationBuilder.DropTable(
name: "PhoneModels");
}
}
}