using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace Moonlight.Api.Database.Migrations { /// public partial class AddedRolesAndActionTimestamps : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "CreatedAt", schema: "core", table: "Users", type: "timestamp with time zone", nullable: false, defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0))); migrationBuilder.AddColumn( name: "UpdatedAt", schema: "core", table: "Users", type: "timestamp with time zone", nullable: false, defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0))); migrationBuilder.CreateTable( name: "Roles", schema: "core", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "character varying(15)", maxLength: 15, nullable: false), Description = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), Permissions = table.Column(type: "text[]", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Roles", x => x.Id); }); migrationBuilder.CreateTable( name: "RoleMembers", schema: "core", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), RoleId = table.Column(type: "integer", nullable: false), UserId = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_RoleMembers", x => x.Id); table.ForeignKey( name: "FK_RoleMembers_Roles_RoleId", column: x => x.RoleId, principalSchema: "core", principalTable: "Roles", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_RoleMembers_Users_UserId", column: x => x.UserId, principalSchema: "core", principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_RoleMembers_RoleId", schema: "core", table: "RoleMembers", column: "RoleId"); migrationBuilder.CreateIndex( name: "IX_RoleMembers_UserId", schema: "core", table: "RoleMembers", column: "UserId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "RoleMembers", schema: "core"); migrationBuilder.DropTable( name: "Roles", schema: "core"); migrationBuilder.DropColumn( name: "CreatedAt", schema: "core", table: "Users"); migrationBuilder.DropColumn( name: "UpdatedAt", schema: "core", table: "Users"); } } }