From ac769e656b122ff569c3f1534701b71e00fed586 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 27 Oct 2020 19:21:35 +0800 Subject: Split front and back end. --- .../Migrations/20200808071611_UserAddUniqueId.cs | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 BackEnd/Timeline/Migrations/20200808071611_UserAddUniqueId.cs (limited to 'BackEnd/Timeline/Migrations/20200808071611_UserAddUniqueId.cs') diff --git a/BackEnd/Timeline/Migrations/20200808071611_UserAddUniqueId.cs b/BackEnd/Timeline/Migrations/20200808071611_UserAddUniqueId.cs new file mode 100644 index 00000000..651a2b05 --- /dev/null +++ b/BackEnd/Timeline/Migrations/20200808071611_UserAddUniqueId.cs @@ -0,0 +1,55 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Timeline.Migrations +{ + public partial class UserAddUniqueId : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql( +@" +PRAGMA foreign_keys=OFF; + +BEGIN TRANSACTION; + +CREATE TABLE new_users ( + id INTEGER NOT NULL + CONSTRAINT PK_users PRIMARY KEY AUTOINCREMENT, + unique_id TEXT NOT NULL DEFAULT (lower(hex(randomblob(16)))), + username TEXT NOT NULL, + password TEXT NOT NULL, + roles TEXT NOT NULL, + version INTEGER NOT NULL + DEFAULT 0, + nickname TEXT +); + +INSERT INTO new_users (id, username, password, roles, version, nickname) + SELECT id, username, password, roles, version, nickname FROM users; + +DROP TABLE users; + +ALTER TABLE new_users + RENAME TO users; + +CREATE UNIQUE INDEX IX_users_username ON users ( + username +); + +PRAGMA foreign_key_check; + +COMMIT TRANSACTION; + +PRAGMA foreign_keys=ON; +" + , true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "unique_id", + table: "users"); + } + } +} -- cgit v1.2.3