Добавлены слои данных: контекс, сущности и миграции
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,251 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
[Migration("20261023140810_InitialSchema")]
|
||||
partial class InitialSchema
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_text_not_blank", "text ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialSchema : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "chats",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
title = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
history_version = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_chats", x => x.id);
|
||||
table.CheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
table.CheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "users",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
username = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
display_name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
password_hash = table.Column<string>(type: "text", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_users", x => x.id);
|
||||
table.CheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
table.CheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "chat_members",
|
||||
columns: table => new
|
||||
{
|
||||
chat_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
user_id = table.Column<Guid>(type: "uuid", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_chat_members", x => new { x.chat_id, x.user_id });
|
||||
table.ForeignKey(
|
||||
name: "fk_chat_members_chats_chat_id",
|
||||
column: x => x.chat_id,
|
||||
principalTable: "chats",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_chat_members_users_user_id",
|
||||
column: x => x.user_id,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "sessions",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
token_hash = table.Column<byte[]>(type: "bytea", nullable: false),
|
||||
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
expires_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
revoked_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_sessions", x => x.id);
|
||||
table.CheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
table.CheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
table.ForeignKey(
|
||||
name: "fk_sessions_users_user_id",
|
||||
column: x => x.user_id,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "messages",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
chat_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
sender_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
text = table.Column<string>(type: "character varying(4000)", maxLength: 4000, nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_messages", x => x.id);
|
||||
table.CheckConstraint("ck_messages_text_not_blank", "text ~ '\\S'");
|
||||
table.ForeignKey(
|
||||
name: "fk_messages_chat_members_chat_id_sender_id",
|
||||
columns: x => new { x.chat_id, x.sender_id },
|
||||
principalTable: "chat_members",
|
||||
principalColumns: new[] { "chat_id", "user_id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_chat_members_user_id",
|
||||
table: "chat_members",
|
||||
column: "user_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_chats_created_at_id",
|
||||
table: "chats",
|
||||
columns: new[] { "created_at", "id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_messages_chat_history",
|
||||
table: "messages",
|
||||
columns: new[] { "chat_id", "created_at", "id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_messages_chat_id_sender_id",
|
||||
table: "messages",
|
||||
columns: new[] { "chat_id", "sender_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_sessions_expires_at",
|
||||
table: "sessions",
|
||||
column: "expires_at");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_sessions_user_id",
|
||||
table: "sessions",
|
||||
column: "user_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ux_sessions_token_hash",
|
||||
table: "sessions",
|
||||
column: "token_hash",
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ux_users_username",
|
||||
table: "users",
|
||||
column: "username",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "messages");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "sessions");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "chat_members");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "chats");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "users");
|
||||
}
|
||||
}
|
||||
}
|
||||
+255
@@ -0,0 +1,255 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Messenger.Api.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
[DbContext(typeof(MessengerDbContext))]
|
||||
[Migration("20261023170730_AddChatLastMessageAt")]
|
||||
partial class AddChatLastMessageAt
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "10.0.13")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<long>("HistoryVersion")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint")
|
||||
.HasDefaultValue(0L)
|
||||
.HasColumnName("history_version");
|
||||
|
||||
b.Property<DateTimeOffset?>("LastMessageAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("last_message_at");
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("title");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_chats");
|
||||
|
||||
b.HasIndex("CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_chats_created_at_id");
|
||||
|
||||
b.ToTable("chats", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_chats_history_version_nonneg", "history_version >= 0");
|
||||
|
||||
t.HasCheckConstraint("ck_chats_title_not_blank", "title ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("ChatId", "UserId")
|
||||
.HasName("pk_chat_members");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_chat_members_user_id");
|
||||
|
||||
b.ToTable("chat_members", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<Guid>("ChatId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("chat_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<Guid>("SenderId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("sender_id");
|
||||
|
||||
b.Property<string>("Text")
|
||||
.IsRequired()
|
||||
.HasMaxLength(4000)
|
||||
.HasColumnType("character varying(4000)")
|
||||
.HasColumnName("text");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_messages");
|
||||
|
||||
b.HasIndex("ChatId", "SenderId")
|
||||
.HasDatabaseName("ix_messages_chat_id_sender_id");
|
||||
|
||||
b.HasIndex("ChatId", "CreatedAt", "Id")
|
||||
.HasDatabaseName("ix_messages_chat_history");
|
||||
|
||||
b.ToTable("messages", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_messages_text_not_blank", "text ~ '\\S'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<DateTimeOffset>("ExpiresAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expires_at");
|
||||
|
||||
b.Property<DateTimeOffset?>("RevokedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("revoked_at");
|
||||
|
||||
b.Property<byte[]>("TokenHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("bytea")
|
||||
.HasColumnName("token_hash");
|
||||
|
||||
b.Property<Guid>("UserId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("user_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_sessions");
|
||||
|
||||
b.HasIndex("ExpiresAt")
|
||||
.HasDatabaseName("ix_sessions_expires_at");
|
||||
|
||||
b.HasIndex("TokenHash")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_sessions_token_hash");
|
||||
|
||||
b.HasIndex("UserId")
|
||||
.HasDatabaseName("ix_sessions_user_id");
|
||||
|
||||
b.ToTable("sessions", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_sessions_expiry_after_creation", "expires_at > created_at");
|
||||
|
||||
t.HasCheckConstraint("ck_sessions_token_hash_len", "octet_length(token_hash) = 32");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.UserEntity", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreatedAt")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("created_at");
|
||||
|
||||
b.Property<string>("DisplayName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("display_name");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("password_hash");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("username");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_users");
|
||||
|
||||
b.HasIndex("Username")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ux_users_username");
|
||||
|
||||
b.ToTable("users", null, t =>
|
||||
{
|
||||
t.HasCheckConstraint("ck_users_display_name_not_blank", "display_name ~ '\\S'");
|
||||
|
||||
t.HasCheckConstraint("ck_users_username_format", "username ~ '^[a-z0-9_]{3,32}$'");
|
||||
});
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.ChatMemberEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_chats_chat_id");
|
||||
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_chat_members_users_user_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.MessageEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.ChatMemberEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("ChatId", "SenderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_messages_chat_members_chat_id_sender_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Messenger.Api.Data.SessionEntity", b =>
|
||||
{
|
||||
b.HasOne("Messenger.Api.Data.UserEntity", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_sessions_users_user_id");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Messenger.Api.Data.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddChatLastMessageAt : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||
name: "last_message_at",
|
||||
table: "chats",
|
||||
type: "timestamp with time zone",
|
||||
nullable: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "last_message_at",
|
||||
table: "chats");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
// <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.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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user