|
| 1 | +using System; |
| 2 | +using Microsoft.EntityFrameworkCore.Migrations; |
| 3 | + |
| 4 | +#nullable disable |
| 5 | + |
| 6 | +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional |
| 7 | + |
| 8 | +namespace Botticelli.Auth.Data.Sqlite.Migrations |
| 9 | +{ |
| 10 | + /// <inheritdoc /> |
| 11 | + public partial class auth : Migration |
| 12 | + { |
| 13 | + /// <inheritdoc /> |
| 14 | + protected override void Up(MigrationBuilder migrationBuilder) |
| 15 | + { |
| 16 | + migrationBuilder.EnsureSchema( |
| 17 | + name: "Botticelli.Auth.Sample.Telegram"); |
| 18 | + |
| 19 | + migrationBuilder.CreateTable( |
| 20 | + name: "BotUserRoles", |
| 21 | + schema: "Botticelli.Auth.Sample.Telegram", |
| 22 | + columns: table => new |
| 23 | + { |
| 24 | + Id = table.Column<Guid>(type: "TEXT", nullable: false), |
| 25 | + RoleName = table.Column<string>(type: "TEXT", maxLength: 16, nullable: false), |
| 26 | + Description = table.Column<string>(type: "TEXT", maxLength: 1024, nullable: false), |
| 27 | + IsSuperUser = table.Column<bool>(type: "INTEGER", nullable: false) |
| 28 | + }, |
| 29 | + constraints: table => |
| 30 | + { |
| 31 | + table.PrimaryKey("PK_BotUserRoles", x => x.Id); |
| 32 | + }); |
| 33 | + |
| 34 | + migrationBuilder.CreateTable( |
| 35 | + name: "BotUsers", |
| 36 | + schema: "Botticelli.Auth.Sample.Telegram", |
| 37 | + columns: table => new |
| 38 | + { |
| 39 | + UserId = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false), |
| 40 | + UserName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false), |
| 41 | + NickName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true), |
| 42 | + Email = table.Column<string>(type: "TEXT", maxLength: 254, nullable: true), |
| 43 | + FirstName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true), |
| 44 | + LastName = table.Column<string>(type: "TEXT", maxLength: 256, nullable: true), |
| 45 | + Phone = table.Column<string>(type: "TEXT", maxLength: 16, nullable: true), |
| 46 | + RoleId = table.Column<Guid>(type: "TEXT", nullable: false), |
| 47 | + IsActive = table.Column<bool>(type: "INTEGER", nullable: false) |
| 48 | + }, |
| 49 | + constraints: table => |
| 50 | + { |
| 51 | + table.PrimaryKey("PK_BotUsers", x => x.UserId); |
| 52 | + table.ForeignKey( |
| 53 | + name: "FK_BotUsers_BotUserRoles_RoleId", |
| 54 | + column: x => x.RoleId, |
| 55 | + principalSchema: "Botticelli.Auth.Sample.Telegram", |
| 56 | + principalTable: "BotUserRoles", |
| 57 | + principalColumn: "Id", |
| 58 | + onDelete: ReferentialAction.Cascade); |
| 59 | + }); |
| 60 | + |
| 61 | + migrationBuilder.CreateTable( |
| 62 | + name: "AccessHistory", |
| 63 | + schema: "Botticelli.Auth.Sample.Telegram", |
| 64 | + columns: table => new |
| 65 | + { |
| 66 | + Id = table.Column<Guid>(type: "TEXT", nullable: false), |
| 67 | + EntityUserId = table.Column<string>(type: "TEXT", nullable: true), |
| 68 | + TimestampUtc = table.Column<DateTime>(type: "TEXT", nullable: false), |
| 69 | + IsSuccess = table.Column<bool>(type: "INTEGER", nullable: false), |
| 70 | + ErrorMessage = table.Column<string>(type: "TEXT", maxLength: 2048, nullable: true) |
| 71 | + }, |
| 72 | + constraints: table => |
| 73 | + { |
| 74 | + table.PrimaryKey("PK_AccessHistory", x => x.Id); |
| 75 | + table.ForeignKey( |
| 76 | + name: "FK_AccessHistory_BotUsers_EntityUserId", |
| 77 | + column: x => x.EntityUserId, |
| 78 | + principalSchema: "Botticelli.Auth.Sample.Telegram", |
| 79 | + principalTable: "BotUsers", |
| 80 | + principalColumn: "UserId"); |
| 81 | + }); |
| 82 | + |
| 83 | + migrationBuilder.InsertData( |
| 84 | + schema: "Botticelli.Auth.Sample.Telegram", |
| 85 | + table: "BotUserRoles", |
| 86 | + columns: new[] { "Id", "Description", "IsSuperUser", "RoleName" }, |
| 87 | + values: new object[,] |
| 88 | + { |
| 89 | + { new Guid("94854345-5355-4343-3447-1122244f55a8"), "A default authorized user role", false, "User" }, |
| 90 | + { new Guid("9947e363-4255-408d-b277-33402b9f07a1"), "A default user for guest", false, "Guest" }, |
| 91 | + { new Guid("d9887829-61a7-4947-9eb6-7faa66363f08"), "Bot users administrator", true, "Admin" } |
| 92 | + }); |
| 93 | + |
| 94 | + migrationBuilder.CreateIndex( |
| 95 | + name: "IX_AccessHistory_EntityUserId", |
| 96 | + schema: "Botticelli.Auth.Sample.Telegram", |
| 97 | + table: "AccessHistory", |
| 98 | + column: "EntityUserId"); |
| 99 | + |
| 100 | + migrationBuilder.CreateIndex( |
| 101 | + name: "IX_BotUserRoles_RoleName", |
| 102 | + schema: "Botticelli.Auth.Sample.Telegram", |
| 103 | + table: "BotUserRoles", |
| 104 | + column: "RoleName", |
| 105 | + unique: true); |
| 106 | + |
| 107 | + migrationBuilder.CreateIndex( |
| 108 | + name: "IX_BotUsers_RoleId", |
| 109 | + schema: "Botticelli.Auth.Sample.Telegram", |
| 110 | + table: "BotUsers", |
| 111 | + column: "RoleId"); |
| 112 | + } |
| 113 | + |
| 114 | + /// <inheritdoc /> |
| 115 | + protected override void Down(MigrationBuilder migrationBuilder) |
| 116 | + { |
| 117 | + migrationBuilder.DropTable( |
| 118 | + name: "AccessHistory", |
| 119 | + schema: "Botticelli.Auth.Sample.Telegram"); |
| 120 | + |
| 121 | + migrationBuilder.DropTable( |
| 122 | + name: "BotUsers", |
| 123 | + schema: "Botticelli.Auth.Sample.Telegram"); |
| 124 | + |
| 125 | + migrationBuilder.DropTable( |
| 126 | + name: "BotUserRoles", |
| 127 | + schema: "Botticelli.Auth.Sample.Telegram"); |
| 128 | + } |
| 129 | + } |
| 130 | +} |
0 commit comments