blob: e4e41ade573c30f72c78f03758ad2d7a909ca701 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 | 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)
        {
        }
    }
}
 |