using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace HyperBooru.Migrations
{
///
public partial class Initial : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Objects",
columns: table => new
{
ObjectId = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Guid = table.Column(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Objects", x => x.ObjectId);
});
migrationBuilder.CreateTable(
name: "Media",
columns: table => new
{
ObjectId = table.Column(type: "integer", nullable: false),
Checksum = table.Column(type: "text", nullable: false),
MimeType = table.Column(type: "text", nullable: false),
ShortDescription = table.Column(type: "text", nullable: true),
LongDescription = table.Column(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Media", x => x.ObjectId);
table.ForeignKey(
name: "FK_Media_Objects_ObjectId",
column: x => x.ObjectId,
principalTable: "Objects",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TagDefinitions",
columns: table => new
{
ObjectId = table.Column(type: "integer", nullable: false),
Source = table.Column(type: "integer", nullable: false),
Namespace = table.Column(type: "text", nullable: true),
Name = table.Column(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TagDefinitions", x => x.ObjectId);
table.ForeignKey(
name: "FK_TagDefinitions_Objects_ObjectId",
column: x => x.ObjectId,
principalTable: "Objects",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "UploadedFiles",
columns: table => new
{
UploadedFileId = table.Column(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OriginalChecksum = table.Column(type: "text", nullable: false),
Filename = table.Column(type: "text", nullable: true),
UploadTime = table.Column(type: "timestamp with time zone", nullable: false),
LastAccessTime = table.Column(type: "timestamp with time zone", nullable: true),
LastWriteTime = table.Column(type: "timestamp with time zone", nullable: true),
CreateTime = table.Column(type: "timestamp with time zone", nullable: true),
MediaObjectId = table.Column(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UploadedFiles", x => x.UploadedFileId);
table.ForeignKey(
name: "FK_UploadedFiles_Media_MediaObjectId",
column: x => x.MediaObjectId,
principalTable: "Media",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TagDefinitionTagDefinition",
columns: table => new
{
ImplicitTagsObjectId = table.Column(type: "integer", nullable: false),
TagDefinitionObjectId = table.Column(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TagDefinitionTagDefinition", x => new { x.ImplicitTagsObjectId, x.TagDefinitionObjectId });
table.ForeignKey(
name: "FK_TagDefinitionTagDefinition_TagDefinitions_ImplicitTagsObjec~",
column: x => x.ImplicitTagsObjectId,
principalTable: "TagDefinitions",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TagDefinitionTagDefinition_TagDefinitions_TagDefinitionObje~",
column: x => x.TagDefinitionObjectId,
principalTable: "TagDefinitions",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Tags",
columns: table => new
{
ObjectId = table.Column(type: "integer", nullable: false),
TagDefinitionObjectId = table.Column(type: "integer", nullable: false),
CreateTime = table.Column(type: "timestamp with time zone", nullable: false),
TargetObjectId = table.Column(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tags", x => x.ObjectId);
table.ForeignKey(
name: "FK_Tags_Objects_ObjectId",
column: x => x.ObjectId,
principalTable: "Objects",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Tags_Objects_TargetObjectId",
column: x => x.TargetObjectId,
principalTable: "Objects",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Tags_TagDefinitions_TagDefinitionObjectId",
column: x => x.TagDefinitionObjectId,
principalTable: "TagDefinitions",
principalColumn: "ObjectId",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData(
table: "Objects",
columns: new[] { "ObjectId", "Guid" },
values: new object[,]
{
{ -2, new Guid("bab0a0f2-b126-429c-a80e-4f339a1f4bb2") },
{ -1, new Guid("e906ff13-ee7d-4eb2-826b-1cf880590f6b") }
});
migrationBuilder.InsertData(
table: "TagDefinitions",
columns: new[] { "ObjectId", "Name", "Namespace", "Source" },
values: new object[,]
{
{ -2, "ingest", null, 0 },
{ -1, "nsfw", null, 0 }
});
migrationBuilder.CreateIndex(
name: "IX_Objects_Guid",
table: "Objects",
column: "Guid");
migrationBuilder.CreateIndex(
name: "IX_TagDefinitionTagDefinition_TagDefinitionObjectId",
table: "TagDefinitionTagDefinition",
column: "TagDefinitionObjectId");
migrationBuilder.CreateIndex(
name: "IX_Tags_TagDefinitionObjectId",
table: "Tags",
column: "TagDefinitionObjectId");
migrationBuilder.CreateIndex(
name: "IX_Tags_TargetObjectId",
table: "Tags",
column: "TargetObjectId");
migrationBuilder.CreateIndex(
name: "IX_UploadedFiles_MediaObjectId",
table: "UploadedFiles",
column: "MediaObjectId");
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "TagDefinitionTagDefinition");
migrationBuilder.DropTable(
name: "Tags");
migrationBuilder.DropTable(
name: "UploadedFiles");
migrationBuilder.DropTable(
name: "TagDefinitions");
migrationBuilder.DropTable(
name: "Media");
migrationBuilder.DropTable(
name: "Objects");
}
}
}