forked from mtusi2026/mtusi2026lab5
Реализация 5 лабораторной работы
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
namespace Messenger.Api.Data;
|
||||
|
||||
// Используется только командами `dotnet ef`. Для генерации миграций подключение к БД не открывается;
|
||||
// для `dotnet ef database update` строка берётся из MESSENGER_DESIGN_CONNECTION.
|
||||
public sealed class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<MessengerDbContext>
|
||||
{
|
||||
public MessengerDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
var connection = Environment.GetEnvironmentVariable("MESSENGER_DESIGN_CONNECTION")
|
||||
?? "Host=localhost;Database=messenger;Username=design;Password=design";
|
||||
var options = new DbContextOptionsBuilder<MessengerDbContext>()
|
||||
.UseNpgsql(connection)
|
||||
.UseSnakeCaseNamingConvention()
|
||||
.Options;
|
||||
return new MessengerDbContext(options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
namespace Messenger.Api.Data;
|
||||
|
||||
// Долговечное намерение записать S3 object. Создаётся ДО PUT, удаляется атомарно
|
||||
// с публикацией Attachment. После аварии остаётся для фоновой очистки.
|
||||
public sealed class UploadIntentEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string ObjectKey { get; set; } = string.Empty;
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset ExpiresAt { get; set; }
|
||||
public DateTimeOffset NextAttemptAt { get; set; }
|
||||
public int DeleteCount { get; set; }
|
||||
}
|
||||
|
||||
// Строки таблиц. API-модели (Messenger.Api.Models) остаются отдельными: в них нет password_hash и служебных полей.
|
||||
|
||||
public sealed class UserEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string DisplayName { get; set; } = string.Empty;
|
||||
// Результат Argon2id (PHC-строка с солью и параметрами). Наружу не отдаётся никогда.
|
||||
public string PasswordHash { get; set; } = string.Empty;
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ChatEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Title { get; set; } = string.Empty;
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
// Версия истории: растёт на 1 в той же транзакции, что и вставка сообщения (UPDATE ... RETURNING).
|
||||
// Источник версии для ключей кэша; одновременно сериализует записи в один чат (см. DESIGN).
|
||||
public long HistoryVersion { get; set; }
|
||||
|
||||
// Время последнего сообщения. Обновляется тем же UPDATE, что и версия: следующее сообщение получает
|
||||
// created_at строго больше этого значения, поэтому порядок (created_at, id) совпадает с порядком коммитов.
|
||||
public DateTimeOffset? LastMessageAt { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ChatMemberEntity
|
||||
{
|
||||
public Guid ChatId { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
}
|
||||
|
||||
public sealed class MessageEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid ChatId { get; set; }
|
||||
public Guid SenderId { get; set; }
|
||||
public string Text { get; set; } = string.Empty;
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public Guid[] AttachmentIds { get; set; } = [];
|
||||
}
|
||||
|
||||
public sealed class SessionEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
// SHA-256 от токена. Сам токен в БД не хранится: утечка БД не даёт действующих Bearer-токенов.
|
||||
public byte[] TokenHash { get; set; } = Array.Empty<byte>();
|
||||
public Guid UserId { get; set; }
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset ExpiresAt { get; set; }
|
||||
public DateTimeOffset? RevokedAt { get; set; }
|
||||
}
|
||||
|
||||
// Результат идемпотентной отправки сообщения. Область уникальности: пользователь + чат (метод и путь у эндпоинта один:
|
||||
// POST /api/v1/chats/{chat_id}/messages) + ключ. Строка создаётся в той же транзакции, что и сообщение.
|
||||
public sealed class IdempotencyKeyEntity
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public Guid ChatId { get; set; }
|
||||
public string Key { get; set; } = string.Empty;
|
||||
// SHA-256 от смысла запроса (см. IdempotencyKeys.RequestHash): другой хеш при том же ключе → 409.
|
||||
public byte[] RequestHash { get; set; } = Array.Empty<byte>();
|
||||
public Guid MessageId { get; set; }
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset ExpiresAt { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AttachmentEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid ChatId { get; set; }
|
||||
public Guid OwnerId { get; set; }
|
||||
public string Filename { get; set; } = string.Empty;
|
||||
public string ObjectKey { get; set; } = string.Empty;
|
||||
public string ContentType { get; set; } = string.Empty;
|
||||
public long SizeBytes { get; set; }
|
||||
public string ChecksumSha256 { get; set; } = string.Empty;
|
||||
|
||||
public string Status { get; set; } = "queued";
|
||||
public string? ErrorCode { get; set; }
|
||||
public int PipelineVersion { get; set; } = 1;
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public List<AttachmentVariantEntity> Variants { get; set; } = [];
|
||||
}
|
||||
|
||||
// The same row is the processing record and the transactional outbox until publication is confirmed.
|
||||
public sealed class AttachmentJobEntity
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid AttachmentId { get; set; }
|
||||
public AttachmentEntity Attachment { get; set; } = null!;
|
||||
public string SourceKey { get; set; } = string.Empty;
|
||||
public int PipelineVersion { get; set; } = 1;
|
||||
public int Attempt { get; set; } = 1;
|
||||
public int FirstAttempt { get; set; } = 1;
|
||||
public DateTimeOffset? ReplayedAt { get; set; }
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset NextAttemptAt { get; set; }
|
||||
public DateTimeOffset? PublishedAt { get; set; }
|
||||
public DateTimeOffset? LeaseUntil { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AttachmentVariantEntity
|
||||
{
|
||||
public Guid AttachmentId { get; set; }
|
||||
public int PipelineVersion { get; set; }
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string ObjectKey { get; set; } = string.Empty;
|
||||
public string ContentType { get; set; } = string.Empty;
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
public long SizeBytes { get; set; }
|
||||
public string Sha256 { get; set; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Messenger.Api.Data;
|
||||
|
||||
public sealed class MessengerDbContext(DbContextOptions<MessengerDbContext> options) : DbContext(options)
|
||||
{
|
||||
public DbSet<UserEntity> Users => Set<UserEntity>();
|
||||
public DbSet<ChatEntity> Chats => Set<ChatEntity>();
|
||||
public DbSet<ChatMemberEntity> ChatMembers => Set<ChatMemberEntity>();
|
||||
public DbSet<MessageEntity> Messages => Set<MessageEntity>();
|
||||
public DbSet<SessionEntity> Sessions => Set<SessionEntity>();
|
||||
public DbSet<IdempotencyKeyEntity> IdempotencyKeys => Set<IdempotencyKeyEntity>();
|
||||
public DbSet<AttachmentEntity> Attachments => Set<AttachmentEntity>();
|
||||
public DbSet<UploadIntentEntity> UploadIntents => Set<UploadIntentEntity>();
|
||||
public DbSet<AttachmentJobEntity> AttachmentJobs => Set<AttachmentJobEntity>();
|
||||
public DbSet<AttachmentVariantEntity> AttachmentVariants => Set<AttachmentVariantEntity>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<UploadIntentEntity>(e =>
|
||||
{
|
||||
e.ToTable("upload_intents");
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedNever();
|
||||
e.Property(x => x.ObjectKey).IsRequired();
|
||||
e.HasIndex(x => x.ObjectKey).IsUnique();
|
||||
e.HasIndex(x => new { x.NextAttemptAt, x.ExpiresAt });
|
||||
});
|
||||
// Идентификаторы создаёт приложение (Guid.CreateVersion7: монотонные, индексы вставляются «справа»).
|
||||
// Время created_at тоже назначает приложение, а не DEFAULT now(): см. порядок операций отправки сообщения.
|
||||
|
||||
modelBuilder.Entity<UserEntity>(e =>
|
||||
{
|
||||
e.ToTable("users", t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_username_format", @"username ~ '^[a-z0-9_]{3,32}$'");
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", @"display_name ~ '\S'");
|
||||
});
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedNever();
|
||||
e.Property(x => x.Username).HasMaxLength(32).IsRequired();
|
||||
e.Property(x => x.DisplayName).HasMaxLength(100).IsRequired(); // varchar(n) считает символы, не байты
|
||||
e.Property(x => x.PasswordHash).IsRequired();
|
||||
e.Property(x => x.CreatedAt).IsRequired();
|
||||
e.HasIndex(x => x.Username).IsUnique().HasDatabaseName("ux_users_username");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ChatEntity>(e =>
|
||||
{
|
||||
e.ToTable("chats", t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", @"title ~ '\S'");
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
});
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedNever();
|
||||
e.Property(x => x.Title).HasMaxLength(100).IsRequired();
|
||||
e.Property(x => x.CreatedAt).IsRequired();
|
||||
e.Property(x => x.HistoryVersion).HasDefaultValue(0L).IsRequired();
|
||||
// Список чатов: сортировка по (created_at, id) с keyset-курсором.
|
||||
e.HasIndex(x => new { x.CreatedAt, x.Id }).HasDatabaseName("ix_chats_created_at_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<ChatMemberEntity>(e =>
|
||||
{
|
||||
e.ToTable("chat_members");
|
||||
e.HasKey(x => new { x.ChatId, x.UserId }); // один пользователь не может быть в чате дважды
|
||||
e.HasOne<ChatEntity>().WithMany().HasForeignKey(x => x.ChatId).OnDelete(DeleteBehavior.Cascade);
|
||||
e.HasOne<UserEntity>().WithMany().HasForeignKey(x => x.UserId).OnDelete(DeleteBehavior.Restrict);
|
||||
// PK обслуживает «участники чата»; этот индекс — «чаты пользователя» и проверку доступа.
|
||||
e.HasIndex(x => x.UserId).HasDatabaseName("ix_chat_members_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<MessageEntity>(e =>
|
||||
{
|
||||
e.ToTable("messages", t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_text_or_attachments", @"text ~ '\S' OR cardinality(attachment_ids) > 0");
|
||||
t.HasCheckConstraint("ck_messages_attachment_limit", "cardinality(attachment_ids) <= 10");
|
||||
});
|
||||
// До 10 ссылок: храним порядок без дополнительных запросов для каждой строки истории.
|
||||
e.Property(x => x.AttachmentIds).HasColumnType("uuid[]").HasDefaultValueSql("'{}'::uuid[]").IsRequired();
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedNever();
|
||||
e.Property(x => x.Text).HasMaxLength(4000).IsRequired();
|
||||
e.Property(x => x.CreatedAt).IsRequired();
|
||||
// Составной FK: отправитель обязан быть участником именно этого чата. Он же гарантирует существование
|
||||
// чата и пользователя, поэтому отдельные FK на chats/users не нужны.
|
||||
e.HasOne<ChatMemberEntity>().WithMany()
|
||||
.HasForeignKey(x => new { x.ChatId, x.SenderId })
|
||||
.HasPrincipalKey(x => new { x.ChatId, x.UserId })
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
// Страница истории: WHERE chat_id = @c AND (created_at, id) > (@t, @i) ORDER BY created_at, id LIMIT n.
|
||||
e.HasIndex(x => new { x.ChatId, x.CreatedAt, x.Id }).HasDatabaseName("ix_messages_chat_history");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<SessionEntity>(e =>
|
||||
{
|
||||
e.ToTable("sessions", t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
});
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedNever();
|
||||
e.Property(x => x.TokenHash).IsRequired();
|
||||
e.Property(x => x.CreatedAt).IsRequired();
|
||||
e.Property(x => x.ExpiresAt).IsRequired();
|
||||
e.HasOne<UserEntity>().WithMany().HasForeignKey(x => x.UserId).OnDelete(DeleteBehavior.Cascade);
|
||||
// Аутентификация каждого запроса: поиск по хешу токена.
|
||||
e.HasIndex(x => x.TokenHash).IsUnique().HasDatabaseName("ux_sessions_token_hash");
|
||||
// Фоновая очистка истёкших сессий.
|
||||
e.HasIndex(x => x.ExpiresAt).HasDatabaseName("ix_sessions_expires_at");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<IdempotencyKeyEntity>(e =>
|
||||
{
|
||||
e.ToTable("idempotency_keys", t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_idempotency_keys_hash_len", "octet_length(request_hash) = 32");
|
||||
t.HasCheckConstraint("ck_idempotency_keys_expiry", "expires_at > created_at");
|
||||
});
|
||||
// PK = область уникальности. Именно его уникальный индекс заставляет конкурентные запросы с одним ключом
|
||||
// ждать друг друга. FK на messages(id) (DEFERRABLE INITIALLY DEFERRED) добавлен в миграции вручную.
|
||||
e.HasKey(x => new { x.UserId, x.ChatId, x.Key });
|
||||
e.Property(x => x.Key).HasMaxLength(128).IsRequired();
|
||||
e.Property(x => x.RequestHash).IsRequired();
|
||||
e.Property(x => x.CreatedAt).IsRequired();
|
||||
e.Property(x => x.ExpiresAt).IsRequired();
|
||||
// Очистка истёкших ключей.
|
||||
e.HasIndex(x => x.ExpiresAt).HasDatabaseName("ix_idempotency_keys_expires_at");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AttachmentJobEntity>(e =>
|
||||
{
|
||||
e.ToTable("attachment_jobs");
|
||||
e.HasKey(j => j.Id);
|
||||
e.Property(j => j.Id).ValueGeneratedNever();
|
||||
e.Property(j => j.FirstAttempt).HasDefaultValue(1);
|
||||
e.HasOne(j => j.Attachment).WithMany().HasForeignKey(j => j.AttachmentId);
|
||||
e.HasIndex(j => new { j.AttachmentId, j.PipelineVersion }).IsUnique();
|
||||
e.HasIndex(j => j.NextAttemptAt).HasFilter("published_at IS NULL");
|
||||
e.HasIndex(j => j.LeaseUntil).HasFilter("lease_until IS NOT NULL");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AttachmentVariantEntity>(e =>
|
||||
{
|
||||
e.ToTable("attachment_variants");
|
||||
e.HasKey(v => new { v.AttachmentId, v.PipelineVersion, v.Name });
|
||||
e.HasOne<AttachmentEntity>().WithMany(a => a.Variants).HasForeignKey(v => v.AttachmentId);
|
||||
e.HasIndex(v => v.ObjectKey).IsUnique();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<AttachmentEntity>(e =>
|
||||
{
|
||||
e.ToTable("attachments");
|
||||
e.HasKey(x => x.Id);
|
||||
e.Property(x => x.Id).ValueGeneratedNever();
|
||||
|
||||
e.Property(x => x.Filename).HasMaxLength(255).IsRequired();
|
||||
e.Property(x => x.ObjectKey).IsRequired();
|
||||
e.Property(x => x.ContentType).HasMaxLength(100).IsRequired();
|
||||
e.Property(x => x.ChecksumSha256).HasMaxLength(64).IsRequired();
|
||||
e.Property(x => x.Status).HasMaxLength(20).IsRequired();
|
||||
e.Property(x => x.PipelineVersion).HasDefaultValue(1);
|
||||
|
||||
e.HasIndex(x => x.ObjectKey).IsUnique();
|
||||
e.HasIndex(x => x.ChatId);
|
||||
|
||||
e.HasOne<ChatEntity>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.ChatId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
e.HasOne<UserEntity>()
|
||||
.WithMany()
|
||||
.HasForeignKey(x => x.OwnerId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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