301 lines
13 KiB
C#
301 lines
13 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace OnlyPrompt.Backend.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class Initial : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AlterDatabase()
|
|
.Annotation("Npgsql:PostgresExtension:citext", ",,");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Categories",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Slug = table.Column<string>(type: "citext", maxLength: 100, nullable: false),
|
|
Name = table.Column<string>(type: "text", nullable: false),
|
|
Description = table.Column<string>(type: "text", nullable: true),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Categories", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Users",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
UserName = table.Column<string>(type: "citext", maxLength: 100, nullable: false),
|
|
Email = table.Column<string>(type: "citext", nullable: false),
|
|
PasswordHash = table.Column<string>(type: "text", nullable: false),
|
|
Roles = table.Column<string[]>(type: "text[]", nullable: false),
|
|
IsLockoutEnabled = table.Column<bool>(type: "boolean", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Users", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "SubscriptionTiers",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Name = table.Column<string>(type: "text", nullable: false),
|
|
Description = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
|
|
UserId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
MonthlyPrice = table.Column<decimal>(type: "numeric", nullable: false),
|
|
Level = table.Column<int>(type: "integer", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_SubscriptionTiers", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_SubscriptionTiers_Users_UserId",
|
|
column: x => x.UserId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "UserProfiles",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
DisplayName = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
|
Slug = table.Column<string>(type: "citext", maxLength: 100, nullable: false),
|
|
Bio = table.Column<string>(type: "character varying(2000)", maxLength: 2000, nullable: true),
|
|
AvatarUrl = table.Column<string>(type: "text", nullable: false),
|
|
Specialities = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
|
IsPublic = table.Column<bool>(type: "boolean", nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_UserProfiles", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_UserProfiles_Users_Id",
|
|
column: x => x.Id,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Prompts",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
CreatorId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
CategoryId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Title = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
Content = table.Column<string>(type: "text", nullable: false),
|
|
Slug = table.Column<string>(type: "citext", maxLength: 100, nullable: false),
|
|
SubscriptionTierId = table.Column<Guid>(type: "uuid", nullable: true),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Prompts", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Prompts_Categories_CategoryId",
|
|
column: x => x.CategoryId,
|
|
principalTable: "Categories",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_Prompts_SubscriptionTiers_SubscriptionTierId",
|
|
column: x => x.SubscriptionTierId,
|
|
principalTable: "SubscriptionTiers",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_Prompts_Users_CreatorId",
|
|
column: x => x.CreatorId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "UserSubscriptions",
|
|
columns: table => new
|
|
{
|
|
SubscribedToId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
SubscriberId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
SubscriptionTierId = table.Column<Guid>(type: "uuid", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_UserSubscriptions", x => new { x.SubscriberId, x.SubscribedToId });
|
|
table.ForeignKey(
|
|
name: "FK_UserSubscriptions_SubscriptionTiers_SubscriptionTierId",
|
|
column: x => x.SubscriptionTierId,
|
|
principalTable: "SubscriptionTiers",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.SetNull);
|
|
table.ForeignKey(
|
|
name: "FK_UserSubscriptions_Users_SubscribedToId",
|
|
column: x => x.SubscribedToId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_UserSubscriptions_Users_SubscriberId",
|
|
column: x => x.SubscriberId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "Reviews",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
ReviewerId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
PromptId = table.Column<Guid>(type: "uuid", nullable: false),
|
|
Rating = table.Column<int>(type: "integer", nullable: false),
|
|
Comment = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
|
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Reviews", x => x.Id);
|
|
table.ForeignKey(
|
|
name: "FK_Reviews_Prompts_PromptId",
|
|
column: x => x.PromptId,
|
|
principalTable: "Prompts",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "FK_Reviews_Users_ReviewerId",
|
|
column: x => x.ReviewerId,
|
|
principalTable: "Users",
|
|
principalColumn: "Id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Categories_Slug",
|
|
table: "Categories",
|
|
column: "Slug",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Prompts_CategoryId",
|
|
table: "Prompts",
|
|
column: "CategoryId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Prompts_CreatorId",
|
|
table: "Prompts",
|
|
column: "CreatorId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Prompts_Slug",
|
|
table: "Prompts",
|
|
column: "Slug",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Prompts_SubscriptionTierId",
|
|
table: "Prompts",
|
|
column: "SubscriptionTierId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Reviews_PromptId",
|
|
table: "Reviews",
|
|
column: "PromptId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Reviews_ReviewerId_PromptId",
|
|
table: "Reviews",
|
|
columns: new[] { "ReviewerId", "PromptId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_SubscriptionTiers_Level_UserId",
|
|
table: "SubscriptionTiers",
|
|
columns: new[] { "Level", "UserId" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_SubscriptionTiers_UserId",
|
|
table: "SubscriptionTiers",
|
|
column: "UserId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserProfiles_Slug",
|
|
table: "UserProfiles",
|
|
column: "Slug",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Users_Email",
|
|
table: "Users",
|
|
column: "Email",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Users_UserName",
|
|
table: "Users",
|
|
column: "UserName",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserSubscriptions_SubscribedToId",
|
|
table: "UserSubscriptions",
|
|
column: "SubscribedToId");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_UserSubscriptions_SubscriptionTierId",
|
|
table: "UserSubscriptions",
|
|
column: "SubscriptionTierId");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "Reviews");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "UserProfiles");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "UserSubscriptions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Prompts");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Categories");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "SubscriptionTiers");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "Users");
|
|
}
|
|
}
|
|
}
|