aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Migrations/20200810155908_AddTimesToUser.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-31 00:42:06 +0800
committerGitHub <noreply@github.com>2020-10-31 00:42:06 +0800
commit1b80b699e477a0c14a069401cf39126d19668bf0 (patch)
tree0d1c10cd42398bea87e0169e8a4ec385b71f49bc /BackEnd/Timeline/Migrations/20200810155908_AddTimesToUser.cs
parent0062a22423806c9501752132133e14de02355760 (diff)
parent5875e7a19ff8eb244e2849647ba35aa898de6b52 (diff)
downloadtimeline-1b80b699e477a0c14a069401cf39126d19668bf0.tar.gz
timeline-1b80b699e477a0c14a069401cf39126d19668bf0.tar.bz2
timeline-1b80b699e477a0c14a069401cf39126d19668bf0.zip
Merge pull request #161 from crupest/upgrade
Upgrade packages and split front end and back end.
Diffstat (limited to 'BackEnd/Timeline/Migrations/20200810155908_AddTimesToUser.cs')
-rw-r--r--BackEnd/Timeline/Migrations/20200810155908_AddTimesToUser.cs67
1 files changed, 67 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Migrations/20200810155908_AddTimesToUser.cs b/BackEnd/Timeline/Migrations/20200810155908_AddTimesToUser.cs
new file mode 100644
index 00000000..369f85e6
--- /dev/null
+++ b/BackEnd/Timeline/Migrations/20200810155908_AddTimesToUser.cs
@@ -0,0 +1,67 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace Timeline.Migrations
+{
+ public partial class AddTimesToUser : 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,
+ create_time TEXT NOT NULL DEFAULT (datetime('now', 'utc')),
+ last_modified TEXT NOT NULL DEFAULT (datetime('now', 'utc')),
+ username_change_time TEXT NOT NULL DEFAULT (datetime('now', 'utc'))
+);
+
+INSERT INTO new_users (id, unique_id, username, password, roles, version, nickname)
+ SELECT id, unique_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: "create_time",
+ table: "users");
+
+ migrationBuilder.DropColumn(
+ name: "last_modified",
+ table: "users");
+
+ migrationBuilder.DropColumn(
+ name: "username_change_time",
+ table: "users");
+ }
+ }
+}