using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace EchoHub.Server.Data.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "Channels", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), Name = table.Column(type: "TEXT", maxLength: 100, nullable: false), Topic = table.Column(type: "TEXT", maxLength: 500, nullable: true), CreatedAt = table.Column(type: "INTEGER", nullable: false), CreatedByUserId = table.Column(type: "TEXT", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Channels", x => x.Id); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), Username = table.Column(type: "TEXT", maxLength: 50, nullable: false), PasswordHash = table.Column(type: "TEXT", nullable: false), DisplayName = table.Column(type: "TEXT", maxLength: 100, nullable: true), Bio = table.Column(type: "TEXT", maxLength: 500, nullable: true), NicknameColor = table.Column(type: "TEXT", maxLength: 7, nullable: true), AvatarAscii = table.Column(type: "TEXT", maxLength: 10000, nullable: true), Status = table.Column(type: "INTEGER", nullable: false), StatusMessage = table.Column(type: "TEXT", maxLength: 100, nullable: true), CreatedAt = table.Column(type: "INTEGER", nullable: false), LastSeenAt = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); }); migrationBuilder.CreateTable( name: "Messages", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), Content = table.Column(type: "TEXT", maxLength: 2000, nullable: false), Type = table.Column(type: "INTEGER", nullable: false), AttachmentUrl = table.Column(type: "TEXT", maxLength: 500, nullable: true), AttachmentFileName = table.Column(type: "TEXT", maxLength: 255, nullable: true), SentAt = table.Column(type: "INTEGER", nullable: false), ChannelId = table.Column(type: "TEXT", nullable: false), SenderUserId = table.Column(type: "TEXT", nullable: false), SenderUsername = table.Column(type: "TEXT", maxLength: 50, nullable: false) }, constraints: table => { table.PrimaryKey("PK_Messages", x => x.Id); table.ForeignKey( name: "FK_Messages_Channels_ChannelId", column: x => x.ChannelId, principalTable: "Channels", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "RefreshTokens", columns: table => new { Id = table.Column(type: "TEXT", nullable: false), TokenHash = table.Column(type: "TEXT", maxLength: 128, nullable: false), UserId = table.Column(type: "TEXT", nullable: false), ExpiresAt = table.Column(type: "INTEGER", nullable: false), CreatedAt = table.Column(type: "INTEGER", nullable: false), RevokedAt = table.Column(type: "INTEGER", nullable: true) }, constraints: table => { table.PrimaryKey("PK_RefreshTokens", x => x.Id); table.ForeignKey( name: "FK_RefreshTokens_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Channels_Name", table: "Channels", column: "Name", unique: true); migrationBuilder.CreateIndex( name: "IX_Messages_ChannelId", table: "Messages", column: "ChannelId"); migrationBuilder.CreateIndex( name: "IX_Messages_SentAt", table: "Messages", column: "SentAt"); migrationBuilder.CreateIndex( name: "IX_RefreshTokens_TokenHash", table: "RefreshTokens", column: "TokenHash"); migrationBuilder.CreateIndex( name: "IX_RefreshTokens_UserId", table: "RefreshTokens", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Users_Username", table: "Users", column: "Username", unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Messages"); migrationBuilder.DropTable( name: "RefreshTokens"); migrationBuilder.DropTable( name: "Channels"); migrationBuilder.DropTable( name: "Users"); } } }