diff options
author | crupest <crupest@outlook.com> | 2020-08-08 15:47:27 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-08 15:47:27 +0800 |
commit | 5ec61fd4b5dc019893b06aae2590799db38790e7 (patch) | |
tree | a99eb58b6c3abdd5b6f8fde2fa59c37e01deebea /Timeline/Migrations/20200808071611_UserAddUniqueId.cs | |
parent | e0051ef2330f56ff13ca57b7c01059cf4365493e (diff) | |
parent | 7de532360c5e02729f41510bb5d339edc7b378db (diff) | |
download | timeline-5ec61fd4b5dc019893b06aae2590799db38790e7.tar.gz timeline-5ec61fd4b5dc019893b06aae2590799db38790e7.tar.bz2 timeline-5ec61fd4b5dc019893b06aae2590799db38790e7.zip |
Merge pull request #139 from crupest/user-uniqueid
Feature now user also has a unique id.
Diffstat (limited to 'Timeline/Migrations/20200808071611_UserAddUniqueId.cs')
-rw-r--r-- | Timeline/Migrations/20200808071611_UserAddUniqueId.cs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/Timeline/Migrations/20200808071611_UserAddUniqueId.cs b/Timeline/Migrations/20200808071611_UserAddUniqueId.cs new file mode 100644 index 00000000..651a2b05 --- /dev/null +++ b/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");
+ }
+ }
+}
|