using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace FutureMailAPI.Migrations
{
///
public partial class InitialCreate : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Username = table.Column(type: "TEXT", maxLength: 100, nullable: false),
Email = table.Column(type: "TEXT", maxLength: 255, nullable: false),
PasswordHash = table.Column(type: "TEXT", maxLength: 255, nullable: false),
Nickname = table.Column(type: "TEXT", maxLength: 100, nullable: true),
Avatar = table.Column(type: "TEXT", maxLength: 500, nullable: true),
CreatedAt = table.Column(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
LastLoginAt = table.Column(type: "TEXT", nullable: true),
IsActive = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SentMails",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Title = table.Column(type: "TEXT", maxLength: 200, nullable: false),
Content = table.Column(type: "TEXT", nullable: false),
SenderId = table.Column(type: "INTEGER", nullable: false),
RecipientType = table.Column(type: "INTEGER", nullable: false),
RecipientId = table.Column(type: "INTEGER", nullable: true),
SentAt = table.Column(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
DeliveryTime = table.Column(type: "TEXT", nullable: false),
Status = table.Column(type: "INTEGER", nullable: false),
TriggerType = table.Column(type: "INTEGER", nullable: false),
TriggerDetails = table.Column(type: "TEXT", nullable: true),
Attachments = table.Column(type: "TEXT", nullable: true),
IsEncrypted = table.Column(type: "INTEGER", nullable: false),
EncryptionKey = table.Column(type: "TEXT", nullable: true),
Theme = table.Column(type: "TEXT", maxLength: 50, nullable: true),
RecipientId1 = table.Column(type: "INTEGER", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SentMails", x => x.Id);
table.ForeignKey(
name: "FK_SentMails_Users_RecipientId",
column: x => x.RecipientId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "FK_SentMails_Users_RecipientId1",
column: x => x.RecipientId1,
principalTable: "Users",
principalColumn: "Id");
table.ForeignKey(
name: "FK_SentMails_Users_SenderId",
column: x => x.SenderId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "ReceivedMails",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
SentMailId = table.Column(type: "INTEGER", nullable: false),
RecipientId = table.Column(type: "INTEGER", nullable: false),
ReceivedAt = table.Column(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
IsRead = table.Column(type: "INTEGER", nullable: false),
ReadAt = table.Column(type: "TEXT", nullable: true),
IsReplied = table.Column(type: "INTEGER", nullable: false),
ReplyMailId = table.Column(type: "INTEGER", nullable: true),
RecipientId1 = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ReceivedMails", x => x.Id);
table.ForeignKey(
name: "FK_ReceivedMails_SentMails_SentMailId",
column: x => x.SentMailId,
principalTable: "SentMails",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ReceivedMails_Users_RecipientId",
column: x => x.RecipientId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ReceivedMails_Users_RecipientId1",
column: x => x.RecipientId1,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TimeCapsules",
columns: table => new
{
Id = table.Column(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
UserId = table.Column(type: "INTEGER", nullable: false),
SentMailId = table.Column(type: "INTEGER", nullable: false),
PositionX = table.Column(type: "REAL", nullable: false),
PositionY = table.Column(type: "REAL", nullable: false),
PositionZ = table.Column(type: "REAL", nullable: false),
Size = table.Column(type: "REAL", nullable: false),
Color = table.Column(type: "TEXT", maxLength: 20, nullable: true),
Opacity = table.Column(type: "REAL", nullable: false),
Rotation = table.Column(type: "REAL", nullable: false),
Status = table.Column(type: "INTEGER", nullable: false),
Type = table.Column(type: "INTEGER", nullable: false),
CreatedAt = table.Column(type: "TEXT", nullable: false, defaultValueSql: "CURRENT_TIMESTAMP"),
SentMailId1 = table.Column(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TimeCapsules", x => x.Id);
table.ForeignKey(
name: "FK_TimeCapsules_SentMails_SentMailId",
column: x => x.SentMailId,
principalTable: "SentMails",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TimeCapsules_SentMails_SentMailId1",
column: x => x.SentMailId1,
principalTable: "SentMails",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TimeCapsules_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ReceivedMails_RecipientId",
table: "ReceivedMails",
column: "RecipientId");
migrationBuilder.CreateIndex(
name: "IX_ReceivedMails_RecipientId1",
table: "ReceivedMails",
column: "RecipientId1");
migrationBuilder.CreateIndex(
name: "IX_ReceivedMails_SentMailId",
table: "ReceivedMails",
column: "SentMailId");
migrationBuilder.CreateIndex(
name: "IX_SentMails_RecipientId",
table: "SentMails",
column: "RecipientId");
migrationBuilder.CreateIndex(
name: "IX_SentMails_RecipientId1",
table: "SentMails",
column: "RecipientId1");
migrationBuilder.CreateIndex(
name: "IX_SentMails_SenderId",
table: "SentMails",
column: "SenderId");
migrationBuilder.CreateIndex(
name: "IX_TimeCapsules_SentMailId",
table: "TimeCapsules",
column: "SentMailId");
migrationBuilder.CreateIndex(
name: "IX_TimeCapsules_SentMailId1",
table: "TimeCapsules",
column: "SentMailId1");
migrationBuilder.CreateIndex(
name: "IX_TimeCapsules_UserId",
table: "TimeCapsules",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Users_Email",
table: "Users",
column: "Email",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Users_Username",
table: "Users",
column: "Username",
unique: true);
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ReceivedMails");
migrationBuilder.DropTable(
name: "TimeCapsules");
migrationBuilder.DropTable(
name: "SentMails");
migrationBuilder.DropTable(
name: "Users");
}
}
}