using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace CodeLiturgy.Views.Migrations.SiteDb { public partial class Init : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "ApplicationUser", columns: table => new { Id = table.Column(type: "text", nullable: false), UserName = table.Column(type: "text", nullable: true), NormalizedUserName = table.Column(type: "text", nullable: true), Email = table.Column(type: "text", nullable: true), NormalizedEmail = table.Column(type: "text", nullable: true), EmailConfirmed = table.Column(type: "boolean", nullable: false), PasswordHash = table.Column(type: "text", nullable: true), SecurityStamp = table.Column(type: "text", nullable: true), ConcurrencyStamp = table.Column(type: "text", nullable: true), PhoneNumber = table.Column(type: "text", nullable: true), PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), TwoFactorEnabled = table.Column(type: "boolean", nullable: false), LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), LockoutEnabled = table.Column(type: "boolean", nullable: false), AccessFailedCount = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ApplicationUser", x => x.Id); }); migrationBuilder.CreateTable( name: "Roles", columns: table => new { Id = table.Column(type: "text", nullable: false), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), ConcurrencyStamp = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Roles", x => x.Id); }); migrationBuilder.CreateTable( name: "ApplicationUserClaim", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), UserId = table.Column(type: "text", nullable: true), ApplicationUserId = table.Column(type: "text", nullable: true), ClaimType = table.Column(type: "text", nullable: true), ClaimValue = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_ApplicationUserClaim", x => x.Id); table.ForeignKey( name: "FK_ApplicationUserClaim_ApplicationUser_ApplicationUserId", column: x => x.ApplicationUserId, principalTable: "ApplicationUser", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Environments", columns: table => new { Id = table.Column(type: "text", nullable: false), Name = table.Column(type: "text", nullable: true), UserId = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Environments", x => x.Id); table.ForeignKey( name: "FK_Environments_ApplicationUser_UserId", column: x => x.UserId, principalTable: "ApplicationUser", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "RoleClaims", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), RoleId = table.Column(type: "text", nullable: false), ApplicationRoleId = table.Column(type: "text", nullable: true), ClaimType = table.Column(type: "text", nullable: true), ClaimValue = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_RoleClaims", x => x.Id); table.ForeignKey( name: "FK_RoleClaims_Roles_ApplicationRoleId", column: x => x.ApplicationRoleId, principalTable: "Roles", principalColumn: "Id"); table.ForeignKey( name: "FK_RoleClaims_Roles_RoleId", column: x => x.RoleId, principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "UserRole", columns: table => new { UserId = table.Column(type: "text", nullable: false), RoleId = table.Column(type: "text", nullable: false), ApplicationRoleId = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_UserRole", x => new { x.UserId, x.RoleId }); table.ForeignKey( name: "FK_UserRole_ApplicationUser_UserId", column: x => x.UserId, principalTable: "ApplicationUser", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_UserRole_Roles_ApplicationRoleId", column: x => x.ApplicationRoleId, principalTable: "Roles", principalColumn: "Id"); table.ForeignKey( name: "FK_UserRole_Roles_RoleId", column: x => x.RoleId, principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Sites", columns: table => new { Id = table.Column(type: "text", nullable: false), EnvironmentId = table.Column(type: "text", nullable: true), Domain = table.Column(type: "text", nullable: true), UserId = table.Column(type: "text", nullable: true), UrlAddress = table.Column(type: "text", nullable: true), SiteType = table.Column(type: "integer", nullable: false), CreatedDate = table.Column(type: "timestamp with time zone", nullable: false), LastChanged = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Sites", x => x.Id); table.ForeignKey( name: "FK_Sites_ApplicationUser_UserId", column: x => x.UserId, principalTable: "ApplicationUser", principalColumn: "Id"); table.ForeignKey( name: "FK_Sites_Environments_EnvironmentId", column: x => x.EnvironmentId, principalTable: "Environments", principalColumn: "Id"); }); migrationBuilder.CreateIndex( name: "IX_ApplicationUserClaim_ApplicationUserId", table: "ApplicationUserClaim", column: "ApplicationUserId"); migrationBuilder.CreateIndex( name: "IX_Environments_UserId", table: "Environments", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_RoleClaims_ApplicationRoleId", table: "RoleClaims", column: "ApplicationRoleId"); migrationBuilder.CreateIndex( name: "IX_RoleClaims_RoleId", table: "RoleClaims", column: "RoleId"); migrationBuilder.CreateIndex( name: "RoleNameIndex", table: "Roles", column: "NormalizedName", unique: true); migrationBuilder.CreateIndex( name: "IX_Sites_EnvironmentId", table: "Sites", column: "EnvironmentId"); migrationBuilder.CreateIndex( name: "IX_Sites_UserId", table: "Sites", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_UserRole_ApplicationRoleId", table: "UserRole", column: "ApplicationRoleId"); migrationBuilder.CreateIndex( name: "IX_UserRole_RoleId", table: "UserRole", column: "RoleId"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "ApplicationUserClaim"); migrationBuilder.DropTable( name: "RoleClaims"); migrationBuilder.DropTable( name: "Sites"); migrationBuilder.DropTable( name: "UserRole"); migrationBuilder.DropTable( name: "Environments"); migrationBuilder.DropTable( name: "Roles"); migrationBuilder.DropTable( name: "ApplicationUser"); } } }