using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Govor.Data.Migrations { /// public partial class Init : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "ChatGroups", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(100)", maxLength: 100, nullable: false), Description = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), ImageId = table.Column(type: "uuid", nullable: false), IsChannel = table.Column(type: "boolean", nullable: false), IsPrivate = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ChatGroups", x => x.Id); }); migrationBuilder.CreateTable( name: "Invitations", columns: table => new { Id = table.Column(type: "uuid", nullable: false), IsAdmin = table.Column(type: "boolean", nullable: false), IsActive = table.Column(type: "boolean", nullable: false), Code = table.Column(type: "text", nullable: false), Description = table.Column(type: "text", nullable: false), DateCreated = table.Column(type: "timestamp with time zone", nullable: false), EndDate = table.Column(type: "timestamp with time zone", nullable: false), MaxParticipants = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Invitations", x => x.Id); }); migrationBuilder.CreateTable( name: "MediaFiles", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UploaderId = table.Column(type: "uuid", nullable: false), Url = table.Column(type: "text", nullable: false), MediaType = table.Column(type: "text", nullable: false), MineType = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), DateCreated = table.Column(type: "timestamp with time zone", nullable: false), OwnerType = table.Column(type: "integer", nullable: false), OwnerId = table.Column(type: "uuid", nullable: true) }, constraints: table => { table.PrimaryKey("PK_MediaFiles", x => x.Id); }); migrationBuilder.CreateTable( name: "PrivateChats", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserAId = table.Column(type: "uuid", nullable: false), UserBId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PrivateChats", x => x.Id); }); migrationBuilder.CreateTable( name: "UserPushTokens", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), UserSessionId = table.Column(type: "uuid", nullable: true), Token = table.Column(type: "text", nullable: false), Provider = table.Column(type: "text", nullable: false), Platform = table.Column(type: "text", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), LastUsedAt = table.Column(type: "timestamp with time zone", nullable: true), IsActive = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserPushTokens", x => x.Id); }); migrationBuilder.CreateTable( name: "GroupAdmins", columns: table => new { Id = table.Column(type: "uuid", nullable: false), GroupId = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_GroupAdmins", x => x.Id); table.ForeignKey( name: "FK_GroupAdmins_ChatGroups_GroupId", column: x => x.GroupId, principalTable: "ChatGroups", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "uuid", nullable: false), Username = table.Column(type: "character varying(50)", maxLength: 50, nullable: false), Description = table.Column(type: "character varying(500)", maxLength: 500, nullable: true), PasswordHash = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), IconId = table.Column(type: "uuid", nullable: false), CreatedOn = table.Column(type: "date", nullable: false), WasOnline = table.Column(type: "timestamp with time zone", nullable: false), InviteId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); table.ForeignKey( name: "FK_Users_Invitations_InviteId", column: x => x.InviteId, principalTable: "Invitations", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Messages", columns: table => new { Id = table.Column(type: "uuid", nullable: false), SenderId = table.Column(type: "uuid", nullable: false), RecipientId = table.Column(type: "uuid", nullable: false), RecipientType = table.Column(type: "integer", nullable: false), EncryptedContent = table.Column(type: "text", nullable: false), SentAt = table.Column(type: "timestamp with time zone", nullable: false), IsEdited = table.Column(type: "boolean", nullable: false), EditedAt = table.Column(type: "timestamp with time zone", nullable: true), ReplyToMessageId = table.Column(type: "uuid", nullable: true), ChatGroupId = table.Column(type: "uuid", nullable: true), PrivateChatId = table.Column(type: "uuid", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Messages", x => x.Id); table.ForeignKey( name: "FK_Messages_ChatGroups_ChatGroupId", column: x => x.ChatGroupId, principalTable: "ChatGroups", principalColumn: "Id"); table.ForeignKey( name: "FK_Messages_PrivateChats_PrivateChatId", column: x => x.PrivateChatId, principalTable: "PrivateChats", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Admins", columns: table => new { UserId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Admins", x => x.UserId); table.ForeignKey( name: "FK_Admins_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Friendships", columns: table => new { Id = table.Column(type: "uuid", nullable: false), RequesterId = table.Column(type: "uuid", nullable: false), AddresseeId = table.Column(type: "uuid", nullable: false), Status = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Friendships", x => x.Id); table.ForeignKey( name: "FK_Friendships_Users_AddresseeId", column: x => x.AddresseeId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_Friendships_Users_RequesterId", column: x => x.RequesterId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "GroupInvitations", columns: table => new { Id = table.Column(type: "uuid", nullable: false), GroupId = table.Column(type: "uuid", nullable: false), UserMakerId = table.Column(type: "uuid", nullable: false), InvitationCode = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), Description = table.Column(type: "character varying(500)", maxLength: 500, nullable: false), EndDate = table.Column(type: "timestamp with time zone", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), MaxParticipants = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_GroupInvitations", x => x.Id); table.ForeignKey( name: "FK_GroupInvitations_ChatGroups_GroupId", column: x => x.GroupId, principalTable: "ChatGroups", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_GroupInvitations_Users_UserMakerId", column: x => x.UserMakerId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "UserSessions", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), RefreshTokenHash = table.Column(type: "text", nullable: false), DeviceInfo = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), ExpiresAt = table.Column(type: "timestamp with time zone", nullable: false), IsRevoked = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserSessions", x => x.Id); table.ForeignKey( name: "FK_UserSessions_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "MediaAttachments", columns: table => new { Id = table.Column(type: "uuid", nullable: false), MessageId = table.Column(type: "uuid", nullable: false), MediaFileId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_MediaAttachments", x => x.Id); table.ForeignKey( name: "FK_MediaAttachments_MediaFiles_MediaFileId", column: x => x.MediaFileId, principalTable: "MediaFiles", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_MediaAttachments_Messages_MessageId", column: x => x.MessageId, principalTable: "Messages", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "MessageReactions", columns: table => new { Id = table.Column(type: "uuid", nullable: false), MessageId = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), ReactionCode = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), ReactedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_MessageReactions", x => x.Id); table.ForeignKey( name: "FK_MessageReactions_Messages_MessageId", column: x => x.MessageId, principalTable: "Messages", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_MessageReactions_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "MessageViews", columns: table => new { Id = table.Column(type: "uuid", nullable: false), MessageId = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), ViewedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_MessageViews", x => x.Id); table.ForeignKey( name: "FK_MessageViews_Messages_MessageId", column: x => x.MessageId, principalTable: "Messages", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "GroupMemberships", columns: table => new { Id = table.Column(type: "uuid", nullable: false), GroupId = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), InvitationId = table.Column(type: "uuid", nullable: true), IsBanned = table.Column(type: "boolean", nullable: false), MemberSince = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_GroupMemberships", x => x.Id); table.ForeignKey( name: "FK_GroupMemberships_ChatGroups_GroupId", column: x => x.GroupId, principalTable: "ChatGroups", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_GroupMemberships_GroupInvitations_InvitationId", column: x => x.InvitationId, principalTable: "GroupInvitations", principalColumn: "Id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "UserCryptoSessions", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserSessionId = table.Column(type: "uuid", nullable: false), PublicIdentityKey = table.Column(type: "bytea", nullable: false) }, constraints: table => { table.PrimaryKey("PK_UserCryptoSessions", x => x.Id); table.ForeignKey( name: "FK_UserCryptoSessions_UserSessions_UserSessionId", column: x => x.UserSessionId, principalTable: "UserSessions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "OneTimePreKeys", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserCryptoSessionId = table.Column(type: "uuid", nullable: false), PublicKey = table.Column(type: "bytea", nullable: false), IsUsed = table.Column(type: "boolean", nullable: false, defaultValue: false), UploadedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_OneTimePreKeys", x => x.Id); table.ForeignKey( name: "FK_OneTimePreKeys_UserCryptoSessions_UserCryptoSessionId", column: x => x.UserCryptoSessionId, principalTable: "UserCryptoSessions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "SignedPreKeys", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserCryptoSessionId = table.Column(type: "uuid", nullable: false), PublicSignedPreKey = table.Column(type: "bytea", nullable: false), SignedPreKeySignature = table.Column(type: "bytea", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SignedPreKeys", x => x.Id); table.ForeignKey( name: "FK_SignedPreKeys_UserCryptoSessions_UserCryptoSessionId", column: x => x.UserCryptoSessionId, principalTable: "UserCryptoSessions", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Friendships_AddresseeId", table: "Friendships", column: "AddresseeId"); migrationBuilder.CreateIndex( name: "IX_Friendships_Id", table: "Friendships", column: "Id", unique: true); migrationBuilder.CreateIndex( name: "IX_Friendships_RequesterId", table: "Friendships", column: "RequesterId"); migrationBuilder.CreateIndex( name: "IX_GroupAdmins_GroupId", table: "GroupAdmins", column: "GroupId"); migrationBuilder.CreateIndex( name: "IX_GroupInvitations_GroupId", table: "GroupInvitations", column: "GroupId"); migrationBuilder.CreateIndex( name: "IX_GroupInvitations_UserMakerId", table: "GroupInvitations", column: "UserMakerId"); migrationBuilder.CreateIndex( name: "IX_GroupMemberships_GroupId", table: "GroupMemberships", column: "GroupId"); migrationBuilder.CreateIndex( name: "IX_GroupMemberships_InvitationId", table: "GroupMemberships", column: "InvitationId"); migrationBuilder.CreateIndex( name: "IX_MediaAttachments_MediaFileId", table: "MediaAttachments", column: "MediaFileId"); migrationBuilder.CreateIndex( name: "IX_MediaAttachments_MessageId", table: "MediaAttachments", column: "MessageId"); migrationBuilder.CreateIndex( name: "IX_MessageReactions_MessageId_UserId", table: "MessageReactions", columns: new[] { "MessageId", "UserId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_MessageReactions_UserId", table: "MessageReactions", column: "UserId"); migrationBuilder.CreateIndex( name: "IX_Messages_ChatGroupId", table: "Messages", column: "ChatGroupId"); migrationBuilder.CreateIndex( name: "IX_Messages_Id", table: "Messages", column: "Id", unique: true); migrationBuilder.CreateIndex( name: "IX_Messages_PrivateChatId", table: "Messages", column: "PrivateChatId"); migrationBuilder.CreateIndex( name: "IX_Messages_RecipientId", table: "Messages", column: "RecipientId", unique: true); migrationBuilder.CreateIndex( name: "IX_MessageViews_MessageId_UserId", table: "MessageViews", columns: new[] { "MessageId", "UserId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_OneTimePreKeys_UploadedAt", table: "OneTimePreKeys", column: "UploadedAt"); migrationBuilder.CreateIndex( name: "IX_OneTimePreKeys_UserCryptoSessionId_IsUsed", table: "OneTimePreKeys", columns: new[] { "UserCryptoSessionId", "IsUsed" }); migrationBuilder.CreateIndex( name: "IX_PrivateChats_Id", table: "PrivateChats", column: "Id", unique: true); migrationBuilder.CreateIndex( name: "IX_SignedPreKeys_UserCryptoSessionId", table: "SignedPreKeys", column: "UserCryptoSessionId", unique: true); migrationBuilder.CreateIndex( name: "IX_UserCryptoSessions_UserSessionId", table: "UserCryptoSessions", column: "UserSessionId", unique: true); migrationBuilder.CreateIndex( name: "IX_UserPushTokens_Token", table: "UserPushTokens", column: "Token", unique: true); migrationBuilder.CreateIndex( name: "IX_UserPushTokens_UserId", table: "UserPushTokens", column: "UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_UserPushTokens_UserId_IsActive", table: "UserPushTokens", columns: new[] { "UserId", "IsActive" }); migrationBuilder.CreateIndex( name: "IX_UserPushTokens_UserSessionId", table: "UserPushTokens", column: "UserSessionId", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_CreatedOn", table: "Users", column: "CreatedOn"); migrationBuilder.CreateIndex( name: "IX_Users_InviteId", table: "Users", column: "InviteId"); migrationBuilder.CreateIndex( name: "IX_Users_Username", table: "Users", column: "Username", unique: true); migrationBuilder.CreateIndex( name: "IX_Users_WasOnline", table: "Users", column: "WasOnline"); migrationBuilder.CreateIndex( name: "IX_UserSessions_Id", table: "UserSessions", column: "Id", unique: true); migrationBuilder.CreateIndex( name: "IX_UserSessions_RefreshTokenHash", table: "UserSessions", column: "RefreshTokenHash", unique: true); migrationBuilder.CreateIndex( name: "IX_UserSessions_UserId", table: "UserSessions", column: "UserId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Admins"); migrationBuilder.DropTable( name: "Friendships"); migrationBuilder.DropTable( name: "GroupAdmins"); migrationBuilder.DropTable( name: "GroupMemberships"); migrationBuilder.DropTable( name: "MediaAttachments"); migrationBuilder.DropTable( name: "MessageReactions"); migrationBuilder.DropTable( name: "MessageViews"); migrationBuilder.DropTable( name: "OneTimePreKeys"); migrationBuilder.DropTable( name: "SignedPreKeys"); migrationBuilder.DropTable( name: "UserPushTokens"); migrationBuilder.DropTable( name: "GroupInvitations"); migrationBuilder.DropTable( name: "MediaFiles"); migrationBuilder.DropTable( name: "Messages"); migrationBuilder.DropTable( name: "UserCryptoSessions"); migrationBuilder.DropTable( name: "ChatGroups"); migrationBuilder.DropTable( name: "PrivateChats"); migrationBuilder.DropTable( name: "UserSessions"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Invitations"); } } }