✈️ Better migration to new cloud files reference system

This commit is contained in:
2025-06-02 00:49:19 +08:00
parent 00229fd406
commit 3c52a6d787
22 changed files with 562 additions and 190 deletions

View File

@ -19,7 +19,7 @@ using NpgsqlTypes;
namespace DysonNetwork.Sphere.Migrations
{
[DbContext(typeof(AppDatabase))]
[Migration("20250601111032_RefactorCloudFileReference")]
[Migration("20250601142048_RefactorCloudFileReference")]
partial class RefactorCloudFileReference
{
/// <inheritdoc />
@ -540,6 +540,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("background");
b.Property<string>("BackgroundId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("background_id");
b.Property<string>("Bio")
.HasMaxLength(4096)
.HasColumnType("character varying(4096)")
@ -589,6 +594,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("picture");
b.Property<string>("PictureId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("picture_id");
b.Property<string>("Pronouns")
.HasMaxLength(1024)
.HasColumnType("character varying(1024)")
@ -984,6 +994,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("background");
b.Property<string>("BackgroundId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("background_id");
b.Property<Instant>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
@ -1014,6 +1029,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("picture");
b.Property<string>("PictureId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("picture_id");
b.Property<Guid?>("RealmId")
.HasColumnType("uuid")
.HasColumnName("realm_id");
@ -1767,6 +1787,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("background");
b.Property<string>("BackgroundId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("background_id");
b.Property<string>("Bio")
.HasMaxLength(4096)
.HasColumnType("character varying(4096)")
@ -1796,6 +1821,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("picture");
b.Property<string>("PictureId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("picture_id");
b.Property<Guid?>("RealmId")
.HasColumnType("uuid")
.HasColumnName("realm_id");
@ -1967,6 +1997,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("background");
b.Property<string>("BackgroundId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("background_id");
b.Property<Instant>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
@ -1999,6 +2034,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("picture");
b.Property<string>("PictureId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("picture_id");
b.Property<string>("Slug")
.IsRequired()
.HasMaxLength(1024)
@ -2090,12 +2130,10 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnName("deleted_at");
b.Property<CloudFileReferenceObject>("Image")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("image");
b.Property<string>("ImageId")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("image_id");
@ -2217,6 +2255,10 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("character varying(256)")
.HasColumnName("hash");
b.Property<Guid?>("MessageId")
.HasColumnType("uuid")
.HasColumnName("message_id");
b.Property<string>("MimeType")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
@ -2228,6 +2270,10 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("character varying(1024)")
.HasColumnName("name");
b.Property<Guid?>("PostId")
.HasColumnType("uuid")
.HasColumnName("post_id");
b.Property<List<CloudFileSensitiveMark>>("SensitiveMarks")
.HasColumnType("jsonb")
.HasColumnName("sensitive_marks");
@ -2269,6 +2315,12 @@ namespace DysonNetwork.Sphere.Migrations
b.HasIndex("AccountId")
.HasDatabaseName("ix_files_account_id");
b.HasIndex("MessageId")
.HasDatabaseName("ix_files_message_id");
b.HasIndex("PostId")
.HasDatabaseName("ix_files_post_id");
b.ToTable("files", (string)null);
});
@ -3125,6 +3177,16 @@ namespace DysonNetwork.Sphere.Migrations
.IsRequired()
.HasConstraintName("fk_files_accounts_account_id");
b.HasOne("DysonNetwork.Sphere.Chat.Message", null)
.WithMany("OutdatedAttachments")
.HasForeignKey("MessageId")
.HasConstraintName("fk_files_chat_messages_message_id");
b.HasOne("DysonNetwork.Sphere.Post.Post", null)
.WithMany("OutdatedAttachments")
.HasForeignKey("PostId")
.HasConstraintName("fk_files_posts_post_id");
b.Navigation("Account");
});
@ -3285,6 +3347,8 @@ namespace DysonNetwork.Sphere.Migrations
modelBuilder.Entity("DysonNetwork.Sphere.Chat.Message", b =>
{
b.Navigation("OutdatedAttachments");
b.Navigation("Reactions");
});
@ -3297,6 +3361,8 @@ namespace DysonNetwork.Sphere.Migrations
modelBuilder.Entity("DysonNetwork.Sphere.Post.Post", b =>
{
b.Navigation("OutdatedAttachments");
b.Navigation("Reactions");
});

View File

@ -30,14 +30,6 @@ namespace DysonNetwork.Sphere.Migrations
name: "fk_chat_rooms_files_picture_id",
table: "chat_rooms");
migrationBuilder.DropForeignKey(
name: "fk_files_chat_messages_message_id",
table: "files");
migrationBuilder.DropForeignKey(
name: "fk_files_posts_post_id",
table: "files");
migrationBuilder.DropForeignKey(
name: "fk_posts_posts_threaded_post_id",
table: "posts");
@ -86,14 +78,6 @@ namespace DysonNetwork.Sphere.Migrations
name: "ix_posts_threaded_post_id",
table: "posts");
migrationBuilder.DropIndex(
name: "ix_files_message_id",
table: "files");
migrationBuilder.DropIndex(
name: "ix_files_post_id",
table: "files");
migrationBuilder.DropIndex(
name: "ix_chat_rooms_background_id",
table: "chat_rooms");
@ -110,68 +94,39 @@ namespace DysonNetwork.Sphere.Migrations
name: "ix_account_profiles_picture_id",
table: "account_profiles");
migrationBuilder.DropColumn(
name: "background_id",
table: "realms");
migrationBuilder.DropColumn(
name: "picture_id",
table: "realms");
migrationBuilder.DropColumn(
name: "background_id",
table: "publishers");
migrationBuilder.DropColumn(
name: "picture_id",
table: "publishers");
migrationBuilder.DropColumn(
name: "threaded_post_id",
table: "posts");
// TODO Move these following changes to next migrations after migrated all the attachments data
// migrationBuilder.DropColumn(
// name: "expired_at",
// table: "files");
//
// migrationBuilder.DropColumn(
// name: "message_id",
// table: "files");
//
// migrationBuilder.DropColumn(
// name: "post_id",
// table: "files");
//
// migrationBuilder.DropColumn(
// name: "usage",
// table: "files");
//
// migrationBuilder.DropColumn(
// name: "used_count",
// table: "files");
//
// migrationBuilder.DropColumn(
// name: "background_id",
// table: "chat_rooms");
//
// migrationBuilder.DropColumn(
// name: "picture_id",
// table: "chat_rooms");
//
// migrationBuilder.DropColumn(
// name: "background_id",
// table: "account_profiles");
//
// migrationBuilder.DropColumn(
// name: "picture_id",
// table: "account_profiles");
migrationBuilder.DropColumn(
name: "expired_at",
table: "files");
migrationBuilder.DropColumn(
name: "usage",
table: "files");
migrationBuilder.DropColumn(
name: "used_count",
table: "files");
migrationBuilder.AlterColumn<string>(
name: "image_id",
table: "stickers",
type: "character varying(32)",
maxLength: 32,
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(32)",
oldMaxLength: 32);
migrationBuilder.AddColumn<CloudFileReferenceObject>(
name: "image",
table: "stickers",
type: "jsonb",
nullable: false);
nullable: true,
defaultValueSql: "'[]'::jsonb"
);
migrationBuilder.AddColumn<CloudFileReferenceObject>(
name: "background",
@ -201,7 +156,9 @@ namespace DysonNetwork.Sphere.Migrations
name: "attachments",
table: "posts",
type: "jsonb",
nullable: false);
nullable: false,
defaultValueSql: "'[]'::jsonb"
);
migrationBuilder.AddColumn<CloudFileReferenceObject>(
name: "background",
@ -219,7 +176,9 @@ namespace DysonNetwork.Sphere.Migrations
name: "attachments",
table: "chat_messages",
type: "jsonb",
nullable: false);
nullable: false,
defaultValueSql: "'[]'::jsonb"
);
migrationBuilder.AddColumn<CloudFileReferenceObject>(
name: "background",
@ -313,33 +272,17 @@ namespace DysonNetwork.Sphere.Migrations
name: "picture",
table: "account_profiles");
migrationBuilder.AddColumn<string>(
name: "background_id",
table: "realms",
migrationBuilder.AlterColumn<string>(
name: "image_id",
table: "stickers",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "picture_id",
table: "realms",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "background_id",
table: "publishers",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "picture_id",
table: "publishers",
type: "character varying(32)",
maxLength: 32,
nullable: true);
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "character varying(32)",
oldMaxLength: 32,
oldNullable: true);
migrationBuilder.AddColumn<Guid>(
name: "threaded_post_id",
@ -353,18 +296,6 @@ namespace DysonNetwork.Sphere.Migrations
type: "timestamp with time zone",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "message_id",
table: "files",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "post_id",
table: "files",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "usage",
table: "files",
@ -379,34 +310,6 @@ namespace DysonNetwork.Sphere.Migrations
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<string>(
name: "background_id",
table: "chat_rooms",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "picture_id",
table: "chat_rooms",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "background_id",
table: "account_profiles",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "picture_id",
table: "account_profiles",
type: "character varying(32)",
maxLength: 32,
nullable: true);
migrationBuilder.CreateIndex(
name: "ix_stickers_image_id",
table: "stickers",
@ -438,16 +341,6 @@ namespace DysonNetwork.Sphere.Migrations
column: "threaded_post_id",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_files_message_id",
table: "files",
column: "message_id");
migrationBuilder.CreateIndex(
name: "ix_files_post_id",
table: "files",
column: "post_id");
migrationBuilder.CreateIndex(
name: "ix_chat_rooms_background_id",
table: "chat_rooms",
@ -496,20 +389,6 @@ namespace DysonNetwork.Sphere.Migrations
principalTable: "files",
principalColumn: "id");
migrationBuilder.AddForeignKey(
name: "fk_files_chat_messages_message_id",
table: "files",
column: "message_id",
principalTable: "chat_messages",
principalColumn: "id");
migrationBuilder.AddForeignKey(
name: "fk_files_posts_post_id",
table: "files",
column: "post_id",
principalTable: "posts",
principalColumn: "id");
migrationBuilder.AddForeignKey(
name: "fk_posts_posts_threaded_post_id",
table: "posts",

View File

@ -537,6 +537,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("background");
b.Property<string>("BackgroundId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("background_id");
b.Property<string>("Bio")
.HasMaxLength(4096)
.HasColumnType("character varying(4096)")
@ -586,6 +591,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("picture");
b.Property<string>("PictureId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("picture_id");
b.Property<string>("Pronouns")
.HasMaxLength(1024)
.HasColumnType("character varying(1024)")
@ -981,6 +991,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("background");
b.Property<string>("BackgroundId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("background_id");
b.Property<Instant>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
@ -1011,6 +1026,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("picture");
b.Property<string>("PictureId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("picture_id");
b.Property<Guid?>("RealmId")
.HasColumnType("uuid")
.HasColumnName("realm_id");
@ -1764,6 +1784,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("background");
b.Property<string>("BackgroundId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("background_id");
b.Property<string>("Bio")
.HasMaxLength(4096)
.HasColumnType("character varying(4096)")
@ -1793,6 +1818,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("picture");
b.Property<string>("PictureId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("picture_id");
b.Property<Guid?>("RealmId")
.HasColumnType("uuid")
.HasColumnName("realm_id");
@ -1964,6 +1994,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("background");
b.Property<string>("BackgroundId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("background_id");
b.Property<Instant>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
@ -1996,6 +2031,11 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("jsonb")
.HasColumnName("picture");
b.Property<string>("PictureId")
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("picture_id");
b.Property<string>("Slug")
.IsRequired()
.HasMaxLength(1024)
@ -2087,12 +2127,10 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnName("deleted_at");
b.Property<CloudFileReferenceObject>("Image")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("image");
b.Property<string>("ImageId")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("image_id");
@ -2214,6 +2252,10 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("character varying(256)")
.HasColumnName("hash");
b.Property<Guid?>("MessageId")
.HasColumnType("uuid")
.HasColumnName("message_id");
b.Property<string>("MimeType")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
@ -2225,6 +2267,10 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("character varying(1024)")
.HasColumnName("name");
b.Property<Guid?>("PostId")
.HasColumnType("uuid")
.HasColumnName("post_id");
b.Property<List<CloudFileSensitiveMark>>("SensitiveMarks")
.HasColumnType("jsonb")
.HasColumnName("sensitive_marks");
@ -2266,6 +2312,12 @@ namespace DysonNetwork.Sphere.Migrations
b.HasIndex("AccountId")
.HasDatabaseName("ix_files_account_id");
b.HasIndex("MessageId")
.HasDatabaseName("ix_files_message_id");
b.HasIndex("PostId")
.HasDatabaseName("ix_files_post_id");
b.ToTable("files", (string)null);
});
@ -3122,6 +3174,16 @@ namespace DysonNetwork.Sphere.Migrations
.IsRequired()
.HasConstraintName("fk_files_accounts_account_id");
b.HasOne("DysonNetwork.Sphere.Chat.Message", null)
.WithMany("OutdatedAttachments")
.HasForeignKey("MessageId")
.HasConstraintName("fk_files_chat_messages_message_id");
b.HasOne("DysonNetwork.Sphere.Post.Post", null)
.WithMany("OutdatedAttachments")
.HasForeignKey("PostId")
.HasConstraintName("fk_files_posts_post_id");
b.Navigation("Account");
});
@ -3282,6 +3344,8 @@ namespace DysonNetwork.Sphere.Migrations
modelBuilder.Entity("DysonNetwork.Sphere.Chat.Message", b =>
{
b.Navigation("OutdatedAttachments");
b.Navigation("Reactions");
});
@ -3294,6 +3358,8 @@ namespace DysonNetwork.Sphere.Migrations
modelBuilder.Entity("DysonNetwork.Sphere.Post.Post", b =>
{
b.Navigation("OutdatedAttachments");
b.Navigation("Reactions");
});