aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Migrations/20200229103848_AddPostLocalId.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-02-29 19:32:58 +0800
committercrupest <crupest@outlook.com>2020-02-29 19:32:58 +0800
commit3025536a7901da556bc5e3fba7a77064b54796c0 (patch)
treeb4f26809215caf4fc31be5a097819f5ad2f2a9d3 /Timeline/Migrations/20200229103848_AddPostLocalId.cs
parentb6b6c3089d42adc3d39aeb5efcbce7bdef09b3cb (diff)
downloadtimeline-3025536a7901da556bc5e3fba7a77064b54796c0.tar.gz
timeline-3025536a7901da556bc5e3fba7a77064b54796c0.tar.bz2
timeline-3025536a7901da556bc5e3fba7a77064b54796c0.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.cs42
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)
+ {
+
+ }
+ }
+}