forked from mtusi2026/mtusi2026lab5
58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
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'");
|
|
}
|
|
}
|
|
}
|