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 | db65d0c37ace61701deec5cc9cd74239208e0935 (patch) | |
tree | 8847b5500a529b6b62e11fb0a3db742be9c0210e /Timeline/Migrations/20200808071611_UserAddUniqueId.cs | |
parent | 151105f387c65f2285f61f8e492ad06734ec9f64 (diff) | |
parent | 976f1d9d7062aaedca52cdd6398576b717b5f58f (diff) | |
download | timeline-db65d0c37ace61701deec5cc9cd74239208e0935.tar.gz timeline-db65d0c37ace61701deec5cc9cd74239208e0935.tar.bz2 timeline-db65d0c37ace61701deec5cc9cd74239208e0935.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");
+ }
+ }
+}
|