forked from mtusi2026/mtusi2026lab5
Реализация 5 лабораторной работы
This commit is contained in:
@@ -0,0 +1,251 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
[Migration("20261023140810_InitialSchema")]
|
||||
partial class InitialSchema
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_text_not_blank", "text ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialSchema : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "chats",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
title = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
history_version = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_chats", x => x.id);
|
||||
table.CheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
table.CheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "users",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
username = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
display_name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
password_hash = table.Column<string>(type: "text", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_users", x => x.id);
|
||||
table.CheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
table.CheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "chat_members",
|
||||
columns: table => new
|
||||
{
|
||||
chat_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
user_id = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_chat_members", x => new { x.chat_id, x.user_id });
|
||||
table.ForeignKey(
|
||||
name: "fk_chat_members_chats_chat_id",
|
||||
column: x => x.chat_id,
|
||||
principalTable: "chats",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_chat_members_users_user_id",
|
||||
column: x => x.user_id,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "sessions",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
token_hash = table.Column<byte[]>(type: "bytea", nullable: false),
|
||||
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
expires_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
revoked_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_sessions", x => x.id);
|
||||
table.CheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
table.CheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
table.ForeignKey(
|
||||
name: "fk_sessions_users_user_id",
|
||||
column: x => x.user_id,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "messages",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
chat_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
sender_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
text = table.Column<string>(type: "character varying(4000)", maxLength: 4000, nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_messages", x => x.id);
|
||||
table.CheckConstraint("ck_messages_text_not_blank", "text ~ '\\S'");
|
||||
table.ForeignKey(
|
||||
name: "fk_messages_chat_members_chat_id_sender_id",
|
||||
columns: x => new { x.chat_id, x.sender_id },
|
||||
principalTable: "chat_members",
|
||||
principalColumns: new[] { "chat_id", "user_id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_chat_members_user_id",
|
||||
table: "chat_members",
|
||||
column: "user_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_chats_created_at_id",
|
||||
table: "chats",
|
||||
columns: new[] { "created_at", "id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_messages_chat_history",
|
||||
table: "messages",
|
||||
columns: new[] { "chat_id", "created_at", "id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_messages_chat_id_sender_id",
|
||||
table: "messages",
|
||||
columns: new[] { "chat_id", "sender_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_sessions_expires_at",
|
||||
table: "sessions",
|
||||
column: "expires_at");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_sessions_user_id",
|
||||
table: "sessions",
|
||||
column: "user_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ux_sessions_token_hash",
|
||||
table: "sessions",
|
||||
column: "token_hash",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ux_users_username",
|
||||
table: "users",
|
||||
column: "username",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "messages");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "sessions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "chat_members");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "chats");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "users");
|
||||
}
|
||||
}
|
||||
}
|
||||
+255
@@ -0,0 +1,255 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
[Migration("20261023170730_AddChatLastMessageAt")]
|
||||
partial class AddChatLastMessageAt
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastMessageAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_message_at");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_text_not_blank", "text ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddChatLastMessageAt : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||
name: "last_message_at",
|
||||
table: "chats",
|
||||
type: "timestamp with time zone",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "last_message_at",
|
||||
table: "chats");
|
||||
}
|
||||
}
|
||||
}
|
||||
+301
@@ -0,0 +1,301 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
[Migration("20261106145724_AddIdempotencyKeys")]
|
||||
partial class AddIdempotencyKeys
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastMessageAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_message_at");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.IdempotencyKeyEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("message_id");
|
||||
|
||||
b.Property<byte[]>("RequestHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("request_hash");
|
||||
|
||||
b.HasKey("UserId", "ChatId", "Key")
|
||||
.HasName("pk_idempotency_keys");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_idempotency_keys_expires_at");
|
||||
|
||||
b.ToTable("idempotency_keys", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_idempotency_keys_expiry", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_idempotency_keys_hash_len", "octet_length(request_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_text_not_blank", "text ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddIdempotencyKeys : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "idempotency_keys",
|
||||
columns: table => new
|
||||
{
|
||||
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
chat_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
key = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: false),
|
||||
request_hash = table.Column<byte[]>(type: "bytea", nullable: false),
|
||||
message_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
expires_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_idempotency_keys", x => new { x.user_id, x.chat_id, x.key });
|
||||
table.CheckConstraint("ck_idempotency_keys_expiry", "expires_at > created_at");
|
||||
table.CheckConstraint("ck_idempotency_keys_hash_len", "octet_length(request_hash) = 32");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_idempotency_keys_expires_at",
|
||||
table: "idempotency_keys",
|
||||
column: "expires_at");
|
||||
|
||||
// Ключ идемпотентности вставляется РАНЬШЕ сообщения (claim → резервирование слота → вставка), поэтому FK
|
||||
// проверяется при COMMIT (DEFERRABLE INITIALLY DEFERRED): запись «ключ → сообщение» без сообщения не переживёт транзакцию.
|
||||
// Миграция только добавляет таблицу: запущенная предыдущая версия API её не использует и продолжает работать
|
||||
// (совместимость для rolling update).
|
||||
migrationBuilder.Sql("""
|
||||
ALTER TABLE idempotency_keys
|
||||
ADD CONSTRAINT fk_idempotency_keys_messages_message_id
|
||||
FOREIGN KEY (message_id) REFERENCES messages (id) ON DELETE CASCADE
|
||||
DEFERRABLE INITIALLY DEFERRED;
|
||||
""");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "idempotency_keys");
|
||||
}
|
||||
}
|
||||
}
|
||||
+389
@@ -0,0 +1,389 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
[Migration("20261113163634_AddAttachments")]
|
||||
partial class AddAttachments
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("ChecksumSha256")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("checksum_sha256");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("content_type");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("Filename")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("filename");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.Property<Guid>("OwnerId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("owner_id");
|
||||
|
||||
b.Property<long>("SizeBytes")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("size_bytes");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("character varying(20)")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<DateTimeOffset?>("UploadedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("uploaded_at");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_attachments");
|
||||
|
||||
b.HasIndex("ChatId")
|
||||
.HasDatabaseName("ix_attachments_chat_id");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachments_object_key");
|
||||
|
||||
b.HasIndex("OwnerId")
|
||||
.HasDatabaseName("ix_attachments_owner_id");
|
||||
|
||||
b.ToTable("attachments", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastMessageAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_message_at");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.IdempotencyKeyEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("message_id");
|
||||
|
||||
b.Property<byte[]>("RequestHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("request_hash");
|
||||
|
||||
b.HasKey("UserId", "ChatId", "Key")
|
||||
.HasName("pk_idempotency_keys");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_idempotency_keys_expires_at");
|
||||
|
||||
b.ToTable("idempotency_keys", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_idempotency_keys_expiry", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_idempotency_keys_hash_len", "octet_length(request_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_text_not_blank", "text ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("OwnerId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_users_owner_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddAttachments : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "attachments",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
chat_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
owner_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
filename = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
|
||||
object_key = table.Column<string>(type: "text", nullable: false),
|
||||
content_type = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
size_bytes = table.Column<long>(type: "bigint", nullable: false),
|
||||
checksum_sha256 = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
|
||||
status = table.Column<string>(type: "character varying(20)", maxLength: 20, nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
uploaded_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_attachments", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "fk_attachments_chats_chat_id",
|
||||
column: x => x.chat_id,
|
||||
principalTable: "chats",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_attachments_users_owner_id",
|
||||
column: x => x.owner_id,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_attachments_chat_id",
|
||||
table: "attachments",
|
||||
column: "chat_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_attachments_object_key",
|
||||
table: "attachments",
|
||||
column: "object_key",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_attachments_owner_id",
|
||||
table: "attachments",
|
||||
column: "owner_id");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "attachments");
|
||||
}
|
||||
}
|
||||
}
|
||||
+398
@@ -0,0 +1,398 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
[Migration("20261113171218_AddMessageAttachments")]
|
||||
partial class AddMessageAttachments
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("ChecksumSha256")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("checksum_sha256");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("content_type");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("Filename")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("filename");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.Property<Guid>("OwnerId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("owner_id");
|
||||
|
||||
b.Property<long>("SizeBytes")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("size_bytes");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("character varying(20)")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<DateTimeOffset?>("UploadedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("uploaded_at");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_attachments");
|
||||
|
||||
b.HasIndex("ChatId")
|
||||
.HasDatabaseName("ix_attachments_chat_id");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachments_object_key");
|
||||
|
||||
b.HasIndex("OwnerId")
|
||||
.HasDatabaseName("ix_attachments_owner_id");
|
||||
|
||||
b.ToTable("attachments", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastMessageAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_message_at");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.IdempotencyKeyEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("message_id");
|
||||
|
||||
b.Property<byte[]>("RequestHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("request_hash");
|
||||
|
||||
b.HasKey("UserId", "ChatId", "Key")
|
||||
.HasName("pk_idempotency_keys");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_idempotency_keys_expires_at");
|
||||
|
||||
b.ToTable("idempotency_keys", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_idempotency_keys_expiry", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_idempotency_keys_hash_len", "octet_length(request_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.PrimitiveCollection<Guid[]>("AttachmentIds")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid[]")
|
||||
.HasColumnName("attachment_ids")
|
||||
.HasDefaultValueSql("'{}'::uuid[]");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_attachment_limit", "cardinality(attachment_ids) <= 10");
|
||||
|
||||
t.HasCheckConstraint("ck_messages_text_or_attachments", "text ~ '\\S' OR cardinality(attachment_ids) > 0");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("OwnerId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_users_owner_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddMessageAttachments : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "ck_messages_text_not_blank",
|
||||
table: "messages");
|
||||
|
||||
migrationBuilder.AddColumn<Guid[]>(
|
||||
name: "attachment_ids",
|
||||
table: "messages",
|
||||
type: "uuid[]",
|
||||
nullable: false,
|
||||
defaultValueSql: "'{}'::uuid[]");
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "ck_messages_attachment_limit",
|
||||
table: "messages",
|
||||
sql: "cardinality(attachment_ids) <= 10");
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "ck_messages_text_or_attachments",
|
||||
table: "messages",
|
||||
sql: "text ~ '\\S' OR cardinality(attachment_ids) > 0");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "ck_messages_attachment_limit",
|
||||
table: "messages");
|
||||
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "ck_messages_text_or_attachments",
|
||||
table: "messages");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "attachment_ids",
|
||||
table: "messages");
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "ck_messages_text_not_blank",
|
||||
table: "messages",
|
||||
sql: "text ~ '\\S'");
|
||||
}
|
||||
}
|
||||
}
|
||||
+438
@@ -0,0 +1,438 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
[Migration("20261113175727_AddUploadIntents")]
|
||||
partial class AddUploadIntents
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("ChecksumSha256")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("checksum_sha256");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("content_type");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("Filename")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("filename");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.Property<Guid>("OwnerId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("owner_id");
|
||||
|
||||
b.Property<long>("SizeBytes")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("size_bytes");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("character varying(20)")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<DateTimeOffset?>("UploadedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("uploaded_at");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_attachments");
|
||||
|
||||
b.HasIndex("ChatId")
|
||||
.HasDatabaseName("ix_attachments_chat_id");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachments_object_key");
|
||||
|
||||
b.HasIndex("OwnerId")
|
||||
.HasDatabaseName("ix_attachments_owner_id");
|
||||
|
||||
b.ToTable("attachments", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastMessageAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_message_at");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.IdempotencyKeyEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("message_id");
|
||||
|
||||
b.Property<byte[]>("RequestHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("request_hash");
|
||||
|
||||
b.HasKey("UserId", "ChatId", "Key")
|
||||
.HasName("pk_idempotency_keys");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_idempotency_keys_expires_at");
|
||||
|
||||
b.ToTable("idempotency_keys", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_idempotency_keys_expiry", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_idempotency_keys_hash_len", "octet_length(request_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.PrimitiveCollection<Guid[]>("AttachmentIds")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid[]")
|
||||
.HasColumnName("attachment_ids")
|
||||
.HasDefaultValueSql("'{}'::uuid[]");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_attachment_limit", "cardinality(attachment_ids) <= 10");
|
||||
|
||||
t.HasCheckConstraint("ck_messages_text_or_attachments", "text ~ '\\S' OR cardinality(attachment_ids) > 0");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UploadIntentEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<int>("DeleteCount")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("delete_count");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset>("NextAttemptAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("next_attempt_at");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_upload_intents");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_upload_intents_object_key");
|
||||
|
||||
b.HasIndex("NextAttemptAt", "ExpiresAt")
|
||||
.HasDatabaseName("ix_upload_intents_next_attempt_at_expires_at");
|
||||
|
||||
b.ToTable("upload_intents", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("OwnerId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_users_owner_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddUploadIntents : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "upload_intents",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
object_key = table.Column<string>(type: "text", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
expires_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
next_attempt_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
delete_count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_upload_intents", x => x.id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_upload_intents_next_attempt_at_expires_at",
|
||||
table: "upload_intents",
|
||||
columns: new[] { "next_attempt_at", "expires_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_upload_intents_object_key",
|
||||
table: "upload_intents",
|
||||
column: "object_key",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "upload_intents");
|
||||
}
|
||||
}
|
||||
}
|
||||
+577
@@ -0,0 +1,577 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
[Migration("20261127162010_AsyncAttachments")]
|
||||
partial class AsyncAttachments
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("ChecksumSha256")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("checksum_sha256");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("content_type");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("ErrorCode")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("error_code");
|
||||
|
||||
b.Property<string>("Filename")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("filename");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.Property<Guid>("OwnerId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("owner_id");
|
||||
|
||||
b.Property<long>("SizeBytes")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("size_bytes");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("character varying(20)")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<DateTimeOffset?>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_attachments");
|
||||
|
||||
b.HasIndex("ChatId")
|
||||
.HasDatabaseName("ix_attachments_chat_id");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachments_object_key");
|
||||
|
||||
b.HasIndex("OwnerId")
|
||||
.HasDatabaseName("ix_attachments_owner_id");
|
||||
|
||||
b.ToTable("attachments", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentJobEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("AttachmentId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("attachment_id");
|
||||
|
||||
b.Property<int>("Attempt")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("attempt");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("LeaseUntil")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("lease_until");
|
||||
|
||||
b.Property<DateTimeOffset>("NextAttemptAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("next_attempt_at");
|
||||
|
||||
b.Property<int>("PipelineVersion")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("pipeline_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("PublishedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("published_at");
|
||||
|
||||
b.Property<string>("SourceKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("source_key");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_attachment_jobs");
|
||||
|
||||
b.HasIndex("AttachmentId")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachment_jobs_attachment_id");
|
||||
|
||||
b.HasIndex("LeaseUntil")
|
||||
.HasDatabaseName("ix_attachment_jobs_lease_until")
|
||||
.HasFilter("lease_until IS NOT NULL");
|
||||
|
||||
b.HasIndex("NextAttemptAt")
|
||||
.HasDatabaseName("ix_attachment_jobs_next_attempt_at")
|
||||
.HasFilter("published_at IS NULL");
|
||||
|
||||
b.ToTable("attachment_jobs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentVariantEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("AttachmentId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("attachment_id");
|
||||
|
||||
b.Property<int>("PipelineVersion")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("pipeline_version");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("content_type");
|
||||
|
||||
b.Property<int>("Height")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("height");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.Property<string>("Sha256")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("sha256");
|
||||
|
||||
b.Property<long>("SizeBytes")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("size_bytes");
|
||||
|
||||
b.Property<int>("Width")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("width");
|
||||
|
||||
b.HasKey("AttachmentId", "PipelineVersion", "Name")
|
||||
.HasName("pk_attachment_variants");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachment_variants_object_key");
|
||||
|
||||
b.ToTable("attachment_variants", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastMessageAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_message_at");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.IdempotencyKeyEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("message_id");
|
||||
|
||||
b.Property<byte[]>("RequestHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("request_hash");
|
||||
|
||||
b.HasKey("UserId", "ChatId", "Key")
|
||||
.HasName("pk_idempotency_keys");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_idempotency_keys_expires_at");
|
||||
|
||||
b.ToTable("idempotency_keys", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_idempotency_keys_expiry", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_idempotency_keys_hash_len", "octet_length(request_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.PrimitiveCollection<Guid[]>("AttachmentIds")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid[]")
|
||||
.HasColumnName("attachment_ids")
|
||||
.HasDefaultValueSql("'{}'::uuid[]");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_attachment_limit", "cardinality(attachment_ids) <= 10");
|
||||
|
||||
t.HasCheckConstraint("ck_messages_text_or_attachments", "text ~ '\\S' OR cardinality(attachment_ids) > 0");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UploadIntentEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<int>("DeleteCount")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("delete_count");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset>("NextAttemptAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("next_attempt_at");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_upload_intents");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_upload_intents_object_key");
|
||||
|
||||
b.HasIndex("NextAttemptAt", "ExpiresAt")
|
||||
.HasDatabaseName("ix_upload_intents_next_attempt_at_expires_at");
|
||||
|
||||
b.ToTable("upload_intents", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("OwnerId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_users_owner_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentJobEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.AttachmentEntity", "Attachment")
|
||||
.WithOne()
|
||||
.HasForeignKey("Messenger.Api.Data.AttachmentJobEntity", "AttachmentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachment_jobs_attachments_attachment_id");
|
||||
|
||||
b.Navigation("Attachment");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentVariantEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.AttachmentEntity", null)
|
||||
.WithMany("Variants")
|
||||
.HasForeignKey("AttachmentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachment_variants_attachments_attachment_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.Navigation("Variants");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AsyncAttachments : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "uploaded_at",
|
||||
table: "attachments",
|
||||
newName: "updated_at");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "error_code",
|
||||
table: "attachments",
|
||||
type: "text",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "attachment_jobs",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
attachment_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
source_key = table.Column<string>(type: "text", nullable: false),
|
||||
pipeline_version = table.Column<int>(type: "integer", nullable: false),
|
||||
attempt = table.Column<int>(type: "integer", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
next_attempt_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
published_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
lease_until = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_attachment_jobs", x => x.id);
|
||||
table.ForeignKey(
|
||||
name: "fk_attachment_jobs_attachments_attachment_id",
|
||||
column: x => x.attachment_id,
|
||||
principalTable: "attachments",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "attachment_variants",
|
||||
columns: table => new
|
||||
{
|
||||
attachment_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
pipeline_version = table.Column<int>(type: "integer", nullable: false),
|
||||
name = table.Column<string>(type: "text", nullable: false),
|
||||
object_key = table.Column<string>(type: "text", nullable: false),
|
||||
content_type = table.Column<string>(type: "text", nullable: false),
|
||||
width = table.Column<int>(type: "integer", nullable: false),
|
||||
height = table.Column<int>(type: "integer", nullable: false),
|
||||
size_bytes = table.Column<long>(type: "bigint", nullable: false),
|
||||
sha256 = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_attachment_variants", x => new { x.attachment_id, x.pipeline_version, x.name });
|
||||
table.ForeignKey(
|
||||
name: "fk_attachment_variants_attachments_attachment_id",
|
||||
column: x => x.attachment_id,
|
||||
principalTable: "attachments",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_attachment_jobs_attachment_id",
|
||||
table: "attachment_jobs",
|
||||
column: "attachment_id",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_attachment_jobs_lease_until",
|
||||
table: "attachment_jobs",
|
||||
column: "lease_until",
|
||||
filter: "lease_until IS NOT NULL");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_attachment_jobs_next_attempt_at",
|
||||
table: "attachment_jobs",
|
||||
column: "next_attempt_at",
|
||||
filter: "published_at IS NULL");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_attachment_variants_object_key",
|
||||
table: "attachment_variants",
|
||||
column: "object_key",
|
||||
unique: true);
|
||||
|
||||
// Старые originals уже устойчивы. Обрабатываем их на месте, сохраняя ID и ссылки сообщений.
|
||||
migrationBuilder.Sql("""
|
||||
INSERT INTO attachment_jobs (id, attachment_id, source_key, pipeline_version, attempt, created_at, next_attempt_at)
|
||||
SELECT gen_random_uuid(), id, object_key, 1, 1, now(), now() FROM attachments WHERE status = 'ready';
|
||||
UPDATE attachments SET status = 'queued', updated_at = now() WHERE status = 'ready';
|
||||
""");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql("""
|
||||
DO $$ BEGIN
|
||||
IF EXISTS (SELECT 1 FROM attachments WHERE status <> 'ready') THEN
|
||||
RAISE EXCEPTION 'Lab4 requires a published original for every attachment';
|
||||
END IF;
|
||||
END $$;
|
||||
""");
|
||||
migrationBuilder.DropTable(
|
||||
name: "attachment_jobs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "attachment_variants");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "error_code",
|
||||
table: "attachments");
|
||||
|
||||
migrationBuilder.RenameColumn(
|
||||
name: "updated_at",
|
||||
table: "attachments",
|
||||
newName: "uploaded_at");
|
||||
}
|
||||
}
|
||||
}
|
||||
+593
@@ -0,0 +1,593 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
[Migration("20261127163030_VersionedAttachmentJobs")]
|
||||
partial class VersionedAttachmentJobs
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("ChecksumSha256")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("checksum_sha256");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("content_type");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("ErrorCode")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("error_code");
|
||||
|
||||
b.Property<string>("Filename")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("filename");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.Property<Guid>("OwnerId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("owner_id");
|
||||
|
||||
b.Property<int>("PipelineVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(1)
|
||||
.HasColumnName("pipeline_version");
|
||||
|
||||
b.Property<long>("SizeBytes")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("size_bytes");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("character varying(20)")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<DateTimeOffset?>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_attachments");
|
||||
|
||||
b.HasIndex("ChatId")
|
||||
.HasDatabaseName("ix_attachments_chat_id");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachments_object_key");
|
||||
|
||||
b.HasIndex("OwnerId")
|
||||
.HasDatabaseName("ix_attachments_owner_id");
|
||||
|
||||
b.ToTable("attachments", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentJobEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("AttachmentId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("attachment_id");
|
||||
|
||||
b.Property<int>("Attempt")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("attempt");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<int>("FirstAttempt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(1)
|
||||
.HasColumnName("first_attempt");
|
||||
|
||||
b.Property<DateTimeOffset?>("LeaseUntil")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("lease_until");
|
||||
|
||||
b.Property<DateTimeOffset>("NextAttemptAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("next_attempt_at");
|
||||
|
||||
b.Property<int>("PipelineVersion")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("pipeline_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("PublishedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("published_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("ReplayedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("replayed_at");
|
||||
|
||||
b.Property<string>("SourceKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("source_key");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_attachment_jobs");
|
||||
|
||||
b.HasIndex("LeaseUntil")
|
||||
.HasDatabaseName("ix_attachment_jobs_lease_until")
|
||||
.HasFilter("lease_until IS NOT NULL");
|
||||
|
||||
b.HasIndex("NextAttemptAt")
|
||||
.HasDatabaseName("ix_attachment_jobs_next_attempt_at")
|
||||
.HasFilter("published_at IS NULL");
|
||||
|
||||
b.HasIndex("AttachmentId", "PipelineVersion")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachment_jobs_attachment_id_pipeline_version");
|
||||
|
||||
b.ToTable("attachment_jobs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentVariantEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("AttachmentId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("attachment_id");
|
||||
|
||||
b.Property<int>("PipelineVersion")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("pipeline_version");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("content_type");
|
||||
|
||||
b.Property<int>("Height")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("height");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.Property<string>("Sha256")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("sha256");
|
||||
|
||||
b.Property<long>("SizeBytes")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("size_bytes");
|
||||
|
||||
b.Property<int>("Width")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("width");
|
||||
|
||||
b.HasKey("AttachmentId", "PipelineVersion", "Name")
|
||||
.HasName("pk_attachment_variants");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachment_variants_object_key");
|
||||
|
||||
b.ToTable("attachment_variants", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastMessageAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_message_at");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.IdempotencyKeyEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("message_id");
|
||||
|
||||
b.Property<byte[]>("RequestHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("request_hash");
|
||||
|
||||
b.HasKey("UserId", "ChatId", "Key")
|
||||
.HasName("pk_idempotency_keys");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_idempotency_keys_expires_at");
|
||||
|
||||
b.ToTable("idempotency_keys", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_idempotency_keys_expiry", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_idempotency_keys_hash_len", "octet_length(request_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.PrimitiveCollection<Guid[]>("AttachmentIds")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid[]")
|
||||
.HasColumnName("attachment_ids")
|
||||
.HasDefaultValueSql("'{}'::uuid[]");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_attachment_limit", "cardinality(attachment_ids) <= 10");
|
||||
|
||||
t.HasCheckConstraint("ck_messages_text_or_attachments", "text ~ '\\S' OR cardinality(attachment_ids) > 0");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UploadIntentEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<int>("DeleteCount")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("delete_count");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset>("NextAttemptAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("next_attempt_at");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_upload_intents");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_upload_intents_object_key");
|
||||
|
||||
b.HasIndex("NextAttemptAt", "ExpiresAt")
|
||||
.HasDatabaseName("ix_upload_intents_next_attempt_at_expires_at");
|
||||
|
||||
b.ToTable("upload_intents", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("OwnerId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_users_owner_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentJobEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.AttachmentEntity", "Attachment")
|
||||
.WithMany()
|
||||
.HasForeignKey("AttachmentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachment_jobs_attachments_attachment_id");
|
||||
|
||||
b.Navigation("Attachment");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentVariantEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.AttachmentEntity", null)
|
||||
.WithMany("Variants")
|
||||
.HasForeignKey("AttachmentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachment_variants_attachments_attachment_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.Navigation("Variants");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class VersionedAttachmentJobs : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "ix_attachment_jobs_attachment_id",
|
||||
table: "attachment_jobs");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "pipeline_version",
|
||||
table: "attachments",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 1);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "first_attempt",
|
||||
table: "attachment_jobs",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 1);
|
||||
|
||||
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||
name: "replayed_at",
|
||||
table: "attachment_jobs",
|
||||
type: "timestamp with time zone",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_attachment_jobs_attachment_id_pipeline_version",
|
||||
table: "attachment_jobs",
|
||||
columns: new[] { "attachment_id", "pipeline_version" },
|
||||
unique: true);
|
||||
|
||||
// Установки с ранним worker могут хранить только thumbnail. Оригинал уже в S3.
|
||||
migrationBuilder.Sql("""
|
||||
WITH partial AS (
|
||||
UPDATE attachments a SET pipeline_version = 2, status = 'queued', updated_at = now()
|
||||
WHERE status = 'ready' AND NOT EXISTS (
|
||||
SELECT 1 FROM attachment_variants v WHERE v.attachment_id = a.id
|
||||
AND v.pipeline_version = 1 AND v.name = 'optimized'
|
||||
)
|
||||
RETURNING id, object_key
|
||||
)
|
||||
INSERT INTO attachment_jobs (id, attachment_id, source_key, pipeline_version, attempt, created_at, next_attempt_at)
|
||||
SELECT gen_random_uuid(), id, object_key, 2, 1, now(), now() FROM partial;
|
||||
""");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "ix_attachment_jobs_attachment_id_pipeline_version",
|
||||
table: "attachment_jobs");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "pipeline_version",
|
||||
table: "attachments");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "first_attempt",
|
||||
table: "attachment_jobs");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "replayed_at",
|
||||
table: "attachment_jobs");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_attachment_jobs_attachment_id",
|
||||
table: "attachment_jobs",
|
||||
column: "attachment_id",
|
||||
unique: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,590 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
partial class MessengerDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("ChecksumSha256")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("checksum_sha256");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("content_type");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("ErrorCode")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("error_code");
|
||||
|
||||
b.Property<string>("Filename")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("character varying(255)")
|
||||
.HasColumnName("filename");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.Property<Guid>("OwnerId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("owner_id");
|
||||
|
||||
b.Property<int>("PipelineVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(1)
|
||||
.HasColumnName("pipeline_version");
|
||||
|
||||
b.Property<long>("SizeBytes")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("size_bytes");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasMaxLength(20)
|
||||
.HasColumnType("character varying(20)")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<DateTimeOffset?>("UpdatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("updated_at");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_attachments");
|
||||
|
||||
b.HasIndex("ChatId")
|
||||
.HasDatabaseName("ix_attachments_chat_id");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachments_object_key");
|
||||
|
||||
b.HasIndex("OwnerId")
|
||||
.HasDatabaseName("ix_attachments_owner_id");
|
||||
|
||||
b.ToTable("attachments", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentJobEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("AttachmentId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("attachment_id");
|
||||
|
||||
b.Property<int>("Attempt")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("attempt");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<int>("FirstAttempt")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasDefaultValue(1)
|
||||
.HasColumnName("first_attempt");
|
||||
|
||||
b.Property<DateTimeOffset?>("LeaseUntil")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("lease_until");
|
||||
|
||||
b.Property<DateTimeOffset>("NextAttemptAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("next_attempt_at");
|
||||
|
||||
b.Property<int>("PipelineVersion")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("pipeline_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("PublishedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("published_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("ReplayedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("replayed_at");
|
||||
|
||||
b.Property<string>("SourceKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("source_key");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_attachment_jobs");
|
||||
|
||||
b.HasIndex("LeaseUntil")
|
||||
.HasDatabaseName("ix_attachment_jobs_lease_until")
|
||||
.HasFilter("lease_until IS NOT NULL");
|
||||
|
||||
b.HasIndex("NextAttemptAt")
|
||||
.HasDatabaseName("ix_attachment_jobs_next_attempt_at")
|
||||
.HasFilter("published_at IS NULL");
|
||||
|
||||
b.HasIndex("AttachmentId", "PipelineVersion")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachment_jobs_attachment_id_pipeline_version");
|
||||
|
||||
b.ToTable("attachment_jobs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentVariantEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("AttachmentId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("attachment_id");
|
||||
|
||||
b.Property<int>("PipelineVersion")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("pipeline_version");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<string>("ContentType")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("content_type");
|
||||
|
||||
b.Property<int>("Height")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("height");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.Property<string>("Sha256")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("sha256");
|
||||
|
||||
b.Property<long>("SizeBytes")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("size_bytes");
|
||||
|
||||
b.Property<int>("Width")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("width");
|
||||
|
||||
b.HasKey("AttachmentId", "PipelineVersion", "Name")
|
||||
.HasName("pk_attachment_variants");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_attachment_variants_object_key");
|
||||
|
||||
b.ToTable("attachment_variants", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastMessageAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_message_at");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.IdempotencyKeyEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<string>("Key")
|
||||
.HasMaxLength(128)
|
||||
.HasColumnType("character varying(128)")
|
||||
.HasColumnName("key");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<Guid>("MessageId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("message_id");
|
||||
|
||||
b.Property<byte[]>("RequestHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("request_hash");
|
||||
|
||||
b.HasKey("UserId", "ChatId", "Key")
|
||||
.HasName("pk_idempotency_keys");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_idempotency_keys_expires_at");
|
||||
|
||||
b.ToTable("idempotency_keys", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_idempotency_keys_expiry", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_idempotency_keys_hash_len", "octet_length(request_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.PrimitiveCollection<Guid[]>("AttachmentIds")
|
||||
.IsRequired()
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid[]")
|
||||
.HasColumnName("attachment_ids")
|
||||
.HasDefaultValueSql("'{}'::uuid[]");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_attachment_limit", "cardinality(attachment_ids) <= 10");
|
||||
|
||||
t.HasCheckConstraint("ck_messages_text_or_attachments", "text ~ '\\S' OR cardinality(attachment_ids) > 0");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UploadIntentEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<int>("DeleteCount")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("delete_count");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset>("NextAttemptAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("next_attempt_at");
|
||||
|
||||
b.Property<string>("ObjectKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("object_key");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_upload_intents");
|
||||
|
||||
b.HasIndex("ObjectKey")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_upload_intents_object_key");
|
||||
|
||||
b.HasIndex("NextAttemptAt", "ExpiresAt")
|
||||
.HasDatabaseName("ix_upload_intents_next_attempt_at_expires_at");
|
||||
|
||||
b.ToTable("upload_intents", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("OwnerId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachments_users_owner_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentJobEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.AttachmentEntity", "Attachment")
|
||||
.WithMany()
|
||||
.HasForeignKey("AttachmentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachment_jobs_attachments_attachment_id");
|
||||
|
||||
b.Navigation("Attachment");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentVariantEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.AttachmentEntity", null)
|
||||
.WithMany("Variants")
|
||||
.HasForeignKey("AttachmentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_attachment_variants_attachments_attachment_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.AttachmentEntity", b =>
|
||||
{
|
||||
b.Navigation("Variants");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user