diff options
author | crupest <crupest@outlook.com> | 2020-06-13 23:50:09 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-06-13 23:50:09 +0800 |
commit | 2f8ffdb2db682b1c1407313816def20fde58d35f (patch) | |
tree | b824b63e1e7b8f453373bb1c9a3c3644635cd1f0 /Timeline/Migrations/20200613135613_AddTimelineUniqueId.cs | |
parent | eba8e9698c09b805d8ac2a8f58db93b947ac29e3 (diff) | |
download | timeline-2f8ffdb2db682b1c1407313816def20fde58d35f.tar.gz timeline-2f8ffdb2db682b1c1407313816def20fde58d35f.tar.bz2 timeline-2f8ffdb2db682b1c1407313816def20fde58d35f.zip |
feat(back): Add database migration to add unique id for timeline.
Diffstat (limited to 'Timeline/Migrations/20200613135613_AddTimelineUniqueId.cs')
-rw-r--r-- | Timeline/Migrations/20200613135613_AddTimelineUniqueId.cs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Timeline/Migrations/20200613135613_AddTimelineUniqueId.cs b/Timeline/Migrations/20200613135613_AddTimelineUniqueId.cs new file mode 100644 index 00000000..fdca85b2 --- /dev/null +++ b/Timeline/Migrations/20200613135613_AddTimelineUniqueId.cs @@ -0,0 +1,39 @@ +using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace Timeline.Migrations
+{
+ public partial class AddTimelineUniqueId : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.Sql(
+@"
+ALTER TABLE timelines RENAME TO timelines_backup;
+
+CREATE TABLE timelines (
+ id INTEGER NOT NULL CONSTRAINT PK_timelines PRIMARY KEY AUTOINCREMENT,
+ unique_id TEXT NOT NULL DEFAULT (timeline_create_guid()),
+ name TEXT NULL,
+ description TEXT NULL,
+ owner INTEGER NOT NULL,
+ visibility INTEGER NOT NULL,
+ create_time TEXT NOT NULL, current_post_local_id INTEGER NOT NULL DEFAULT 0,
+ CONSTRAINT FK_timelines_users_owner FOREIGN KEY (owner) REFERENCES users (id) ON DELETE CASCADE
+);
+
+INSERT INTO timelines (id, name, description, owner, visibility, create_time)
+ SELECT id, name, description, owner, visibility, create_time FROM timelines_backup;
+
+DROP TABLE timelines_backup;
+"
+ );
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(
+ name: "unique_id",
+ table: "timelines");
+ }
+ }
+}
|