using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace SOR.Database.Migrations.Chat { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.EnsureSchema( name: "chat"); migrationBuilder.CreateTable( name: "channels", schema: "chat", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "text", nullable: false), ChannelType = table.Column(type: "text", nullable: false), MatchId = table.Column(type: "text", nullable: true), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_channels", x => x.Id); }); migrationBuilder.CreateTable( name: "members", schema: "chat", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ChannelId = table.Column(type: "uuid", nullable: false), AccountId = table.Column(type: "uuid", nullable: false), JoinedAt = table.Column(type: "timestamp with time zone", nullable: false), LeftAt = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_members", x => x.Id); table.ForeignKey( name: "FK_members_channels_ChannelId", column: x => x.ChannelId, principalSchema: "chat", principalTable: "channels", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "messages", schema: "chat", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ChannelId = table.Column(type: "uuid", nullable: false), SenderAccountId = table.Column(type: "uuid", nullable: false), Content = table.Column(type: "text", nullable: false), SentAt = table.Column(type: "timestamp with time zone", nullable: false), EditedAt = table.Column(type: "timestamp with time zone", nullable: true), IsDeleted = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_messages", x => x.Id); table.ForeignKey( name: "FK_messages_channels_ChannelId", column: x => x.ChannelId, principalSchema: "chat", principalTable: "channels", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_channels_ChannelType", schema: "chat", table: "channels", column: "ChannelType"); migrationBuilder.CreateIndex( name: "IX_channels_MatchId", schema: "chat", table: "channels", column: "MatchId"); migrationBuilder.CreateIndex( name: "IX_members_AccountId", schema: "chat", table: "members", column: "AccountId"); migrationBuilder.CreateIndex( name: "IX_members_ChannelId_AccountId", schema: "chat", table: "members", columns: new[] { "ChannelId", "AccountId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_messages_ChannelId_SentAt", schema: "chat", table: "messages", columns: new[] { "ChannelId", "SentAt" }); migrationBuilder.CreateIndex( name: "IX_messages_SenderAccountId", schema: "chat", table: "messages", column: "SenderAccountId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "members", schema: "chat"); migrationBuilder.DropTable( name: "messages", schema: "chat"); migrationBuilder.DropTable( name: "channels", schema: "chat"); } } }