using System; using Microsoft.EntityFrameworkCore.Migrations; using NpgsqlTypes; #nullable disable namespace InboxIntel.Infrastructure.Migrations { /// public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "analytics_aggregates", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), Day = table.Column(type: "date", nullable: false), TotalReceived = table.Column(type: "integer", nullable: false), TotalUnread = table.Column(type: "integer", nullable: false), NewsletterCount = table.Column(type: "integer", nullable: false), WithAttachments = table.Column(type: "integer", nullable: false), TotalSizeBytes = table.Column(type: "bigint", nullable: false), HourHistogramJson = table.Column(type: "text", nullable: true), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_analytics_aggregates", x => x.Id); }); migrationBuilder.CreateTable( name: "domains", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), EmailCount = table.Column(type: "integer", nullable: false), IsBulkSender = table.Column(type: "boolean", nullable: false), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_domains", x => x.Id); }); migrationBuilder.CreateTable( name: "labels", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), GmailLabelId = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Name = table.Column(type: "character varying(255)", maxLength: 255, nullable: false), Type = table.Column(type: "text", nullable: false), ColorHex = table.Column(type: "text", nullable: true), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_labels", x => x.Id); }); migrationBuilder.CreateTable( name: "sync_states", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), Status = table.Column(type: "integer", nullable: false), LastSyncType = table.Column(type: "integer", nullable: false), LastHistoryId = table.Column(type: "text", nullable: true), ResumePageToken = table.Column(type: "text", nullable: true), TotalMessagesEstimate = table.Column(type: "integer", nullable: false), MessagesProcessed = table.Column(type: "integer", nullable: false), StartedUtc = table.Column(type: "timestamp with time zone", nullable: true), CompletedUtc = table.Column(type: "timestamp with time zone", nullable: true), LastSuccessfulSyncUtc = table.Column(type: "timestamp with time zone", nullable: true), ConsecutiveFailures = table.Column(type: "integer", nullable: false), LastError = table.Column(type: "character varying(4000)", maxLength: 4000, nullable: true), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_sync_states", x => x.Id); }); migrationBuilder.CreateTable( name: "threads", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), GmailThreadId = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Subject = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true), Snippet = table.Column(type: "text", nullable: true), MessageCount = table.Column(type: "integer", nullable: false), FirstMessageUtc = table.Column(type: "timestamp with time zone", nullable: true), LastMessageUtc = table.Column(type: "timestamp with time zone", nullable: true), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_threads", x => x.Id); }); migrationBuilder.CreateTable( name: "users", columns: table => new { Id = table.Column(type: "uuid", nullable: false), GoogleSubjectId = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), Email = table.Column(type: "character varying(320)", maxLength: 320, nullable: false), DisplayName = table.Column(type: "text", nullable: true), PictureUrl = table.Column(type: "text", nullable: true), EncryptedRefreshToken = table.Column(type: "bytea", nullable: true), AccessTokenExpiresAtUtc = table.Column(type: "timestamp with time zone", nullable: true), LastLoginUtc = table.Column(type: "timestamp with time zone", nullable: true), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_users", x => x.Id); }); migrationBuilder.CreateTable( name: "senders", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), DomainId = table.Column(type: "uuid", nullable: false), Address = table.Column(type: "character varying(320)", maxLength: 320, nullable: false), DisplayName = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), EmailCount = table.Column(type: "integer", nullable: false), UnreadCount = table.Column(type: "integer", nullable: false), TotalSizeBytes = table.Column(type: "bigint", nullable: false), LastReceivedUtc = table.Column(type: "timestamp with time zone", nullable: true), HasUnsubscribe = table.Column(type: "boolean", nullable: false), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_senders", x => x.Id); table.ForeignKey( name: "FK_senders_domains_DomainId", column: x => x.DomainId, principalTable: "domains", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "widget_layouts", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), WidgetKey = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), X = table.Column(type: "integer", nullable: false), Y = table.Column(type: "integer", nullable: false), W = table.Column(type: "integer", nullable: false), H = table.Column(type: "integer", nullable: false), Visible = table.Column(type: "boolean", nullable: false), SortOrder = table.Column(type: "integer", nullable: false), SettingsJson = table.Column(type: "text", nullable: true), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_widget_layouts", x => x.Id); table.ForeignKey( name: "FK_widget_layouts_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "emails", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), GmailMessageId = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), ThreadId = table.Column(type: "uuid", nullable: false), SenderId = table.Column(type: "uuid", nullable: false), Subject = table.Column(type: "character varying(1024)", maxLength: 1024, nullable: true), Snippet = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), BodyText = table.Column(type: "text", nullable: true), SentAtUtc = table.Column(type: "timestamp with time zone", nullable: false), ReceivedAtUtc = table.Column(type: "timestamp with time zone", nullable: true), SizeEstimateBytes = table.Column(type: "bigint", nullable: false), IsUnread = table.Column(type: "boolean", nullable: false), IsStarred = table.Column(type: "boolean", nullable: false), IsImportant = table.Column(type: "boolean", nullable: false), IsInInbox = table.Column(type: "boolean", nullable: false), IsTrashed = table.Column(type: "boolean", nullable: false), HasAttachments = table.Column(type: "boolean", nullable: false), HasListUnsubscribe = table.Column(type: "boolean", nullable: false), ListUnsubscribeRaw = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), SupportsOneClickUnsubscribe = table.Column(type: "boolean", nullable: false), Category = table.Column(type: "integer", nullable: false), SearchVector = table.Column(type: "tsvector", nullable: true, computedColumnSql: "to_tsvector('english', coalesce(\"Subject\",'') || ' ' || coalesce(\"BodyText\",''))", stored: true), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_emails", x => x.Id); table.ForeignKey( name: "FK_emails_senders_SenderId", column: x => x.SenderId, principalTable: "senders", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_emails_threads_ThreadId", column: x => x.ThreadId, principalTable: "threads", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_emails_users_UserId", column: x => x.UserId, principalTable: "users", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "unsubscribe_items", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), SenderId = table.Column(type: "uuid", nullable: false), Method = table.Column(type: "integer", nullable: false), Status = table.Column(type: "integer", nullable: false), UnsubscribeTarget = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true), EmailCount = table.Column(type: "integer", nullable: false), LastAttemptUtc = table.Column(type: "timestamp with time zone", nullable: true), ResultMessage = table.Column(type: "text", nullable: true), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_unsubscribe_items", x => x.Id); table.ForeignKey( name: "FK_unsubscribe_items_senders_SenderId", column: x => x.SenderId, principalTable: "senders", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "attachments", columns: table => new { Id = table.Column(type: "uuid", nullable: false), UserId = table.Column(type: "uuid", nullable: false), EmailId = table.Column(type: "uuid", nullable: false), GmailAttachmentId = table.Column(type: "text", nullable: true), FileName = table.Column(type: "character varying(512)", maxLength: 512, nullable: false), MimeType = table.Column(type: "character varying(255)", maxLength: 255, nullable: true), SizeBytes = table.Column(type: "bigint", nullable: false), CreatedAtUtc = table.Column(type: "timestamp with time zone", nullable: false), UpdatedAtUtc = table.Column(type: "timestamp with time zone", nullable: true) }, constraints: table => { table.PrimaryKey("PK_attachments", x => x.Id); table.ForeignKey( name: "FK_attachments_emails_EmailId", column: x => x.EmailId, principalTable: "emails", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "email_labels", columns: table => new { EmailId = table.Column(type: "uuid", nullable: false), LabelId = table.Column(type: "uuid", nullable: false) }, constraints: table => { table.PrimaryKey("PK_email_labels", x => new { x.EmailId, x.LabelId }); table.ForeignKey( name: "FK_email_labels_emails_EmailId", column: x => x.EmailId, principalTable: "emails", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_email_labels_labels_LabelId", column: x => x.LabelId, principalTable: "labels", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_analytics_aggregates_UserId_Day", table: "analytics_aggregates", columns: new[] { "UserId", "Day" }, unique: true); migrationBuilder.CreateIndex( name: "IX_attachments_EmailId", table: "attachments", column: "EmailId"); migrationBuilder.CreateIndex( name: "IX_attachments_UserId_MimeType", table: "attachments", columns: new[] { "UserId", "MimeType" }); migrationBuilder.CreateIndex( name: "IX_domains_UserId_Name", table: "domains", columns: new[] { "UserId", "Name" }, unique: true); migrationBuilder.CreateIndex( name: "IX_email_labels_LabelId", table: "email_labels", column: "LabelId"); migrationBuilder.CreateIndex( name: "IX_emails_SearchVector", table: "emails", column: "SearchVector") .Annotation("Npgsql:IndexMethod", "GIN"); migrationBuilder.CreateIndex( name: "IX_emails_SenderId", table: "emails", column: "SenderId"); migrationBuilder.CreateIndex( name: "IX_emails_ThreadId", table: "emails", column: "ThreadId"); migrationBuilder.CreateIndex( name: "IX_emails_UserId_Category", table: "emails", columns: new[] { "UserId", "Category" }); migrationBuilder.CreateIndex( name: "IX_emails_UserId_GmailMessageId", table: "emails", columns: new[] { "UserId", "GmailMessageId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_emails_UserId_IsInInbox", table: "emails", columns: new[] { "UserId", "IsInInbox" }); migrationBuilder.CreateIndex( name: "IX_emails_UserId_IsUnread", table: "emails", columns: new[] { "UserId", "IsUnread" }); migrationBuilder.CreateIndex( name: "IX_emails_UserId_SenderId", table: "emails", columns: new[] { "UserId", "SenderId" }); migrationBuilder.CreateIndex( name: "IX_emails_UserId_SentAtUtc", table: "emails", columns: new[] { "UserId", "SentAtUtc" }); migrationBuilder.CreateIndex( name: "IX_labels_UserId_GmailLabelId", table: "labels", columns: new[] { "UserId", "GmailLabelId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_senders_DomainId", table: "senders", column: "DomainId"); migrationBuilder.CreateIndex( name: "IX_senders_UserId_Address", table: "senders", columns: new[] { "UserId", "Address" }, unique: true); migrationBuilder.CreateIndex( name: "IX_senders_UserId_EmailCount", table: "senders", columns: new[] { "UserId", "EmailCount" }); migrationBuilder.CreateIndex( name: "IX_sync_states_UserId", table: "sync_states", column: "UserId", unique: true); migrationBuilder.CreateIndex( name: "IX_threads_UserId_GmailThreadId", table: "threads", columns: new[] { "UserId", "GmailThreadId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_unsubscribe_items_SenderId", table: "unsubscribe_items", column: "SenderId"); migrationBuilder.CreateIndex( name: "IX_unsubscribe_items_UserId_SenderId", table: "unsubscribe_items", columns: new[] { "UserId", "SenderId" }, unique: true); migrationBuilder.CreateIndex( name: "IX_users_Email", table: "users", column: "Email", unique: true); migrationBuilder.CreateIndex( name: "IX_users_GoogleSubjectId", table: "users", column: "GoogleSubjectId", unique: true); migrationBuilder.CreateIndex( name: "IX_widget_layouts_UserId_WidgetKey", table: "widget_layouts", columns: new[] { "UserId", "WidgetKey" }, unique: true); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "analytics_aggregates"); migrationBuilder.DropTable( name: "attachments"); migrationBuilder.DropTable( name: "email_labels"); migrationBuilder.DropTable( name: "sync_states"); migrationBuilder.DropTable( name: "unsubscribe_items"); migrationBuilder.DropTable( name: "widget_layouts"); migrationBuilder.DropTable( name: "emails"); migrationBuilder.DropTable( name: "labels"); migrationBuilder.DropTable( name: "senders"); migrationBuilder.DropTable( name: "threads"); migrationBuilder.DropTable( name: "users"); migrationBuilder.DropTable( name: "domains"); } } }