diff options
author | crupest <crupest@outlook.com> | 2020-10-27 19:21:35 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-10-27 19:21:35 +0800 |
commit | 05ccb4d8f1bbe3fb64e117136b4a89bcfb0b0b33 (patch) | |
tree | 929e514de85eb82a5acb96ecffc6e6d2d95f878f /BackEnd/Timeline/Migrations/20200306110049_AddDataTable.cs | |
parent | 986c6f2e3b858d6332eba0b42acc6861cd4d0227 (diff) | |
download | timeline-05ccb4d8f1bbe3fb64e117136b4a89bcfb0b0b33.tar.gz timeline-05ccb4d8f1bbe3fb64e117136b4a89bcfb0b0b33.tar.bz2 timeline-05ccb4d8f1bbe3fb64e117136b4a89bcfb0b0b33.zip |
Split front and back end.
Diffstat (limited to 'BackEnd/Timeline/Migrations/20200306110049_AddDataTable.cs')
-rw-r--r-- | BackEnd/Timeline/Migrations/20200306110049_AddDataTable.cs | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Migrations/20200306110049_AddDataTable.cs b/BackEnd/Timeline/Migrations/20200306110049_AddDataTable.cs new file mode 100644 index 00000000..e33bf4c9 --- /dev/null +++ b/BackEnd/Timeline/Migrations/20200306110049_AddDataTable.cs @@ -0,0 +1,87 @@ +using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace Timeline.Migrations
+{
+ public partial class AddDataTable : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "data",
+ columns: table => new
+ {
+ id = table.Column<long>(nullable: false)
+ .Annotation("Sqlite:Autoincrement", true),
+ tag = table.Column<string>(nullable: false),
+ data = table.Column<byte[]>(nullable: false),
+ @ref = table.Column<int>(name: "ref", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_data", x => x.id);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_data_tag",
+ table: "data",
+ column: "tag",
+ unique: true);
+
+ migrationBuilder.Sql(@"
+ALTER TABLE user_avatars
+ RENAME TO user_avatars_backup;
+
+CREATE TABLE user_avatars (
+ id INTEGER NOT NULL
+ CONSTRAINT PK_user_avatars PRIMARY KEY AUTOINCREMENT,
+ data_tag TEXT,
+ type TEXT,
+ last_modified TEXT NOT NULL,
+ user INTEGER NOT NULL,
+ CONSTRAINT FK_user_avatars_users_user FOREIGN KEY (
+ user
+ )
+ REFERENCES users (id) ON DELETE CASCADE
+);
+
+INSERT INTO user_avatars (id, data_tag, type, last_modified, user)
+ SELECT id, etag, type, last_modified, user FROM user_avatars_backup;
+
+INSERT OR IGNORE INTO data (tag, data, ref)
+ SELECT etag, data, 0 FROM user_avatars_backup;
+
+UPDATE data
+SET ref = (SELECT COUNT (*)
+ FROM user_avatars_backup AS a
+ WHERE a.etag == data.tag);
+
+DROP TABLE user_avatars_backup;
+
+CREATE UNIQUE INDEX IX_user_avatars_user ON user_avatars (user);
+ ");
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "data");
+
+ migrationBuilder.DropColumn(
+ name: "data_tag",
+ table: "user_avatars");
+
+ migrationBuilder.AddColumn<byte[]>(
+ name: "data",
+ table: "user_avatars",
+ type: "BLOB",
+ nullable: true);
+
+ migrationBuilder.AddColumn<string>(
+ name: "etag",
+ table: "user_avatars",
+ type: "TEXT",
+ nullable: true);
+ }
+ }
+}
|