diff options
author | crupest <crupest@outlook.com> | 2020-02-29 19:32:58 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-02-29 19:32:58 +0800 |
commit | 824da227f6a18c9aa265e5a7b16557b5e22f485f (patch) | |
tree | b4f26809215caf4fc31be5a097819f5ad2f2a9d3 /Timeline/Migrations/20200229103848_AddPostLocalId.cs | |
parent | 11ab08bc1b61636e0681914c62794720e4ac6ac4 (diff) | |
download | timeline-824da227f6a18c9aa265e5a7b16557b5e22f485f.tar.gz timeline-824da227f6a18c9aa265e5a7b16557b5e22f485f.tar.bz2 timeline-824da227f6a18c9aa265e5a7b16557b5e22f485f.zip |
Now posts use local id in same timeline. Also fixed some unconforming place in migrations.
Diffstat (limited to 'Timeline/Migrations/20200229103848_AddPostLocalId.cs')
-rw-r--r-- | Timeline/Migrations/20200229103848_AddPostLocalId.cs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Timeline/Migrations/20200229103848_AddPostLocalId.cs b/Timeline/Migrations/20200229103848_AddPostLocalId.cs new file mode 100644 index 00000000..497b38a1 --- /dev/null +++ b/Timeline/Migrations/20200229103848_AddPostLocalId.cs @@ -0,0 +1,42 @@ +using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace Timeline.Migrations
+{
+ public partial class AddPostLocalId : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+
+ migrationBuilder.AddColumn<long>(
+ name: "current_post_local_id",
+ table: "timelines",
+ nullable: false,
+ defaultValue: 0L);
+
+ migrationBuilder.AddColumn<long>(
+ name: "local_id",
+ table: "timeline_posts",
+ nullable: false,
+ defaultValue: 0L);
+
+ migrationBuilder.Sql(@"
+UPDATE timeline_posts
+SET local_id = (SELECT COUNT (*)
+ FROM timeline_posts AS p
+ WHERE p.timeline = timeline_posts.timeline
+ AND p.id <= timeline_posts.id);
+
+UPDATE timelines
+SET current_post_local_id = (SELECT COUNT (*)
+ FROM timeline_posts AS p
+ WHERE p.timeline = timelines.id);
+ ");
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+
+ }
+ }
+}
|