aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Migrations/20200229103848_AddPostLocalId.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-02-29 19:39:22 +0800
committerGitHub <noreply@github.com>2020-02-29 19:39:22 +0800
commit3f5b4840ff863bed5fd11beb775d02447f022030 (patch)
treeb4f26809215caf4fc31be5a097819f5ad2f2a9d3 /Timeline/Migrations/20200229103848_AddPostLocalId.cs
parentb6b6c3089d42adc3d39aeb5efcbce7bdef09b3cb (diff)
parent3025536a7901da556bc5e3fba7a77064b54796c0 (diff)
downloadtimeline-3f5b4840ff863bed5fd11beb775d02447f022030.tar.gz
timeline-3f5b4840ff863bed5fd11beb775d02447f022030.tar.bz2
timeline-3f5b4840ff863bed5fd11beb775d02447f022030.zip
Merge pull request #67 from crupest/post-local-id
Make posts use local id.
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)
+ {
+
+ }
+ }
+}