using System; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace vassago.Migrations { /// public partial class initialcreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "PermissionSettings", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), MaxAttachmentBytes = table.Column(type: "bigint", nullable: true), MaxTextChars = table.Column(type: "bigint", nullable: true), LinksAllowed = table.Column(type: "boolean", nullable: true), LewdnessFilterLevel = table.Column(type: "integer", nullable: true), MeannessFilterLevel = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_PermissionSettings", x => x.Id); }); migrationBuilder.CreateTable( name: "Channels", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ExternalId = table.Column(type: "numeric(20,0)", nullable: true), DisplayName = table.Column(type: "text", nullable: true), IsDM = table.Column(type: "boolean", nullable: false), PermissionsOverridesId = table.Column(type: "integer", nullable: true), ParentChannelId = table.Column(type: "uuid", nullable: true), ProtocolId = table.Column(type: "uuid", nullable: true), Discriminator = table.Column(type: "text", nullable: false), ConnectionToken = table.Column(type: "text", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Channels", x => x.Id); table.ForeignKey( name: "FK_Channels_Channels_ParentChannelId", column: x => x.ParentChannelId, principalTable: "Channels", principalColumn: "Id"); table.ForeignKey( name: "FK_Channels_Channels_ProtocolId", column: x => x.ProtocolId, principalTable: "Channels", principalColumn: "Id"); table.ForeignKey( name: "FK_Channels_PermissionSettings_PermissionsOverridesId", column: x => x.PermissionsOverridesId, principalTable: "PermissionSettings", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Users", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ExternalId = table.Column(type: "numeric(20,0)", nullable: true), Username = table.Column(type: "text", nullable: true), IsBot = table.Column(type: "boolean", nullable: false), ProtocolId = table.Column(type: "uuid", nullable: true), UserId = table.Column(type: "uuid", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Users", x => x.Id); table.ForeignKey( name: "FK_Users_Channels_ProtocolId", column: x => x.ProtocolId, principalTable: "Channels", principalColumn: "Id"); table.ForeignKey( name: "FK_Users_Users_UserId", column: x => x.UserId, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "ChannelUser", columns: table => new { OtherUsersId = table.Column(type: "uuid", nullable: false), SeenInChannelsId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ChannelUser", x => new { x.OtherUsersId, x.SeenInChannelsId }); table.ForeignKey( name: "FK_ChannelUser_Channels_SeenInChannelsId", column: x => x.SeenInChannelsId, principalTable: "Channels", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_ChannelUser_Users_OtherUsersId", column: x => x.OtherUsersId, principalTable: "Users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Messages", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ExternalId = table.Column(type: "numeric(20,0)", nullable: true), Content = table.Column(type: "text", nullable: true), MentionsMe = table.Column(type: "boolean", nullable: false), Timestamp = table.Column(type: "timestamp with time zone", nullable: false), ActedOn = table.Column(type: "boolean", nullable: false), AuthorId = table.Column(type: "uuid", nullable: true), ChannelId = table.Column(type: "uuid", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Messages", x => x.Id); table.ForeignKey( name: "FK_Messages_Channels_ChannelId", column: x => x.ChannelId, principalTable: "Channels", principalColumn: "Id"); table.ForeignKey( name: "FK_Messages_Users_AuthorId", column: x => x.AuthorId, principalTable: "Users", principalColumn: "Id"); }); migrationBuilder.CreateTable( name: "Attachments", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ExternalId = table.Column(type: "numeric(20,0)", nullable: true), Source = table.Column(type: "text", nullable: true), Content = table.Column(type: "bytea", nullable: true), Filename = table.Column(type: "text", nullable: true), MessageId = table.Column(type: "uuid", nullable: true), ContentType = table.Column(type: "text", nullable: true), Description = table.Column(type: "text", nullable: true), Size = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_Attachments", x => x.Id); table.ForeignKey( name: "FK_Attachments_Messages_MessageId", column: x => x.MessageId, principalTable: "Messages", principalColumn: "Id"); }); migrationBuilder.CreateIndex( name: "IX_Attachments_MessageId", table: "Attachments", column: "MessageId"); migrationBuilder.CreateIndex( name: "IX_Channels_ParentChannelId", table: "Channels", column: "ParentChannelId"); migrationBuilder.CreateIndex( name: "IX_Channels_PermissionsOverridesId", table: "Channels", column: "PermissionsOverridesId"); migrationBuilder.CreateIndex( name: "IX_Channels_ProtocolId", table: "Channels", column: "ProtocolId"); migrationBuilder.CreateIndex( name: "IX_ChannelUser_SeenInChannelsId", table: "ChannelUser", column: "SeenInChannelsId"); migrationBuilder.CreateIndex( name: "IX_Messages_AuthorId", table: "Messages", column: "AuthorId"); migrationBuilder.CreateIndex( name: "IX_Messages_ChannelId", table: "Messages", column: "ChannelId"); migrationBuilder.CreateIndex( name: "IX_Users_ProtocolId", table: "Users", column: "ProtocolId"); migrationBuilder.CreateIndex( name: "IX_Users_UserId", table: "Users", column: "UserId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "Attachments"); migrationBuilder.DropTable( name: "ChannelUser"); migrationBuilder.DropTable( name: "Messages"); migrationBuilder.DropTable( name: "Users"); migrationBuilder.DropTable( name: "Channels"); migrationBuilder.DropTable( name: "PermissionSettings"); } } }