377 lines
18 KiB
C#
377 lines
18 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
|
|
#nullable disable
|
|
|
|
namespace HamyanEdalat.Repository.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class Init : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.EnsureSchema(
|
|
name: "public");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "BlogCategories",
|
|
schema: "public",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Name = table.Column<string>(type: "text", nullable: false),
|
|
Description = table.Column<string>(type: "text", nullable: false),
|
|
RemovedAt = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
|
CreatedBy = table.Column<string>(type: "text", nullable: true),
|
|
IsRemoved = table.Column<bool>(type: "boolean", nullable: false),
|
|
RemovedBy = table.Column<string>(type: "text", nullable: true),
|
|
ModifiedAt = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
|
ModifiedBy = table.Column<string>(type: "text", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_BlogCategories", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Roles",
|
|
schema: "public",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Description = table.Column<string>(type: "text", nullable: false),
|
|
EnglishName = table.Column<string>(type: "text", nullable: false),
|
|
PersianName = table.Column<string>(type: "text", nullable: false),
|
|
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
NormalizedName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Roles", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Users",
|
|
schema: "public",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
FirstName = table.Column<string>(type: "text", nullable: false),
|
|
LastName = table.Column<string>(type: "text", nullable: false),
|
|
NationalId = table.Column<string>(type: "text", nullable: false),
|
|
City = table.Column<string>(type: "text", nullable: false),
|
|
CityId = table.Column<int>(type: "integer", nullable: false),
|
|
BirthDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
|
Gender = table.Column<int>(type: "integer", nullable: false),
|
|
SignUpStatus = table.Column<int>(type: "integer", nullable: false),
|
|
UserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
NormalizedUserName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
Email = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
|
|
NormalizedEmail = table.Column<string>(type: "character varying(256)", maxLength: 256, 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: "Blogs",
|
|
schema: "public",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Title = table.Column<string>(type: "text", nullable: false),
|
|
Content = table.Column<string>(type: "text", nullable: false),
|
|
Tags = table.Column<string>(type: "text", nullable: false),
|
|
ReadingTime = table.Column<int>(type: "integer", nullable: false),
|
|
Summery = table.Column<string>(type: "text", nullable: false),
|
|
IsSuggested = table.Column<bool>(type: "boolean", nullable: false),
|
|
CategoryId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
RemovedAt = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
|
CreatedBy = table.Column<string>(type: "text", nullable: true),
|
|
IsRemoved = table.Column<bool>(type: "boolean", nullable: false),
|
|
RemovedBy = table.Column<string>(type: "text", nullable: true),
|
|
ModifiedAt = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
|
ModifiedBy = table.Column<string>(type: "text", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Blogs", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Blogs_BlogCategories_CategoryId",
|
|
column: x => x.CategoryId,
|
|
principalSchema: "public",
|
|
principalTable: "BlogCategories",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "RoleClaims",
|
|
schema: "public",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
RoleId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
ClaimType = table.Column<string>(type: "text", nullable: true),
|
|
ClaimValue = table.Column<string>(type: "text", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_RoleClaims", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_RoleClaims_Roles_RoleId",
|
|
column: x => x.RoleId,
|
|
principalSchema: "public",
|
|
principalTable: "Roles",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Claims",
|
|
schema: "public",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "integer", nullable: false)
|
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
ClaimType = table.Column<string>(type: "text", nullable: true),
|
|
ClaimValue = table.Column<string>(type: "text", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Claims", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Claims_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalSchema: "public",
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Logins",
|
|
schema: "public",
|
|
columns: table => new
|
|
{
|
|
LoginProvider = table.Column<string>(type: "text", nullable: false),
|
|
ProviderKey = table.Column<string>(type: "text", nullable: false),
|
|
ProviderDisplayName = table.Column<string>(type: "text", nullable: true),
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Logins", x => new { x.LoginProvider, x.ProviderKey });
|
|
table.ForeignKey(
|
|
name: "FK_Logins_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalSchema: "public",
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Tokens",
|
|
schema: "public",
|
|
columns: table => new
|
|
{
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
LoginProvider = table.Column<string>(type: "text", nullable: false),
|
|
Name = table.Column<string>(type: "text", nullable: false),
|
|
Value = table.Column<string>(type: "text", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Tokens", x => new { x.UserId, x.LoginProvider, x.Name });
|
|
table.ForeignKey(
|
|
name: "FK_Tokens_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalSchema: "public",
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "UserRoles",
|
|
schema: "public",
|
|
columns: table => new
|
|
{
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
RoleId = table.Column<Guid>(type: "uuid", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId });
|
|
table.ForeignKey(
|
|
name: "FK_UserRoles_Roles_RoleId",
|
|
column: x => x.RoleId,
|
|
principalSchema: "public",
|
|
principalTable: "Roles",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
table.ForeignKey(
|
|
name: "FK_UserRoles_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalSchema: "public",
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "StorageFiles",
|
|
schema: "public",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Name = table.Column<string>(type: "text", nullable: false),
|
|
FileLocation = table.Column<string>(type: "text", nullable: false),
|
|
FileName = table.Column<string>(type: "text", nullable: false),
|
|
IsHeader = table.Column<bool>(type: "boolean", nullable: false),
|
|
IsPrimary = table.Column<bool>(type: "boolean", nullable: false),
|
|
FileType = table.Column<int>(type: "integer", nullable: false),
|
|
Discriminator = table.Column<string>(type: "character varying(21)", maxLength: 21, nullable: false),
|
|
BlogId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
RemovedAt = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
|
CreatedBy = table.Column<string>(type: "text", nullable: true),
|
|
IsRemoved = table.Column<bool>(type: "boolean", nullable: false),
|
|
RemovedBy = table.Column<string>(type: "text", nullable: true),
|
|
ModifiedAt = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
|
|
ModifiedBy = table.Column<string>(type: "text", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_StorageFiles", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_StorageFiles_Blogs_BlogId",
|
|
column: x => x.BlogId,
|
|
principalSchema: "public",
|
|
principalTable: "Blogs",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Restrict);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Blogs_CategoryId",
|
|
schema: "public",
|
|
table: "Blogs",
|
|
column: "CategoryId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Claims_UserId",
|
|
schema: "public",
|
|
table: "Claims",
|
|
column: "UserId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Logins_UserId",
|
|
schema: "public",
|
|
table: "Logins",
|
|
column: "UserId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_RoleClaims_RoleId",
|
|
schema: "public",
|
|
table: "RoleClaims",
|
|
column: "RoleId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "RoleNameIndex",
|
|
schema: "public",
|
|
table: "Roles",
|
|
column: "NormalizedName",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_StorageFiles_BlogId",
|
|
schema: "public",
|
|
table: "StorageFiles",
|
|
column: "BlogId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserRoles_RoleId",
|
|
schema: "public",
|
|
table: "UserRoles",
|
|
column: "RoleId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "EmailIndex",
|
|
schema: "public",
|
|
table: "Users",
|
|
column: "NormalizedEmail");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "UserNameIndex",
|
|
schema: "public",
|
|
table: "Users",
|
|
column: "NormalizedUserName",
|
|
unique: true);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "Claims",
|
|
schema: "public");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Logins",
|
|
schema: "public");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "RoleClaims",
|
|
schema: "public");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "StorageFiles",
|
|
schema: "public");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Tokens",
|
|
schema: "public");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "UserRoles",
|
|
schema: "public");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Blogs",
|
|
schema: "public");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Roles",
|
|
schema: "public");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Users",
|
|
schema: "public");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "BlogCategories",
|
|
schema: "public");
|
|
}
|
|
}
|
|
}
|