using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Tiku.Infrastructure.Persistence.Migrations
{
///
public partial class AddContentNavigationAndTenantConfiguration : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:PostgresExtension:citext", ",,")
.Annotation("Npgsql:PostgresExtension:ltree", ",,")
.OldAnnotation("Npgsql:PostgresExtension:citext", ",,");
migrationBuilder.AddColumn(
name: "content_node_id",
table: "questions",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn(
name: "entry_id",
table: "questions",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn(
name: "exam_markers",
table: "questions",
type: "jsonb",
nullable: false,
defaultValueSql: "'{}'::jsonb");
migrationBuilder.AddColumn(
name: "primary_collection_id",
table: "questions",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn(
name: "blueprint_id",
table: "practice_sessions",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn(
name: "collection_id",
table: "practice_sessions",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn(
name: "content_node_id",
table: "practice_sessions",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn(
name: "duration_minutes",
table: "practice_sessions",
type: "integer",
nullable: true);
migrationBuilder.AddColumn(
name: "entry_id",
table: "practice_sessions",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn(
name: "expires_at",
table: "practice_sessions",
type: "timestamp with time zone",
nullable: true);
migrationBuilder.AddColumn(
name: "question_count",
table: "practice_sessions",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn(
name: "question_ids",
table: "practice_sessions",
type: "jsonb",
nullable: false,
defaultValueSql: "'[]'::jsonb");
migrationBuilder.AddColumn(
name: "total_score",
table: "practice_sessions",
type: "numeric(8,2)",
precision: 8,
scale: 2,
nullable: true);
migrationBuilder.CreateTable(
name: "content_entries",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column(type: "uuid", nullable: true),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
entry_key = table.Column(type: "character varying(100)", maxLength: 100, nullable: false),
name = table.Column(type: "character varying(300)", maxLength: 300, nullable: false),
entry_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
icon = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
route = table.Column(type: "character varying(500)", maxLength: 500, nullable: true),
description = table.Column(type: "character varying(2000)", maxLength: 2000, nullable: true),
visibility = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
access_rules = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
layout_config = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
sort_order = table.Column(type: "integer", nullable: false),
is_active = table.Column(type: "boolean", nullable: false),
created_by = table.Column(type: "uuid", nullable: true),
updated_by = table.Column(type: "uuid", nullable: true),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_content_entries", x => x.id);
table.UniqueConstraint("ak_content_entries_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_content_entries_regions_tenant_id_region_id",
columns: x => new { x.tenant_id, x.region_id },
principalTable: "regions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_content_entries_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_content_entries_users_created_by",
column: x => x.created_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "fk_content_entries_users_updated_by",
column: x => x.updated_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "tenant_branding",
columns: table => new
{
tenant_id = table.Column(type: "uuid", nullable: false),
brand_name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
short_name = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
slogan = table.Column(type: "character varying(300)", maxLength: 300, nullable: true),
organization_name = table.Column(type: "character varying(300)", maxLength: 300, nullable: true),
logo_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
favicon_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
service_wechat = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
service_account_name = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
theme = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
public_assets = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_tenant_branding", x => x.tenant_id);
table.ForeignKey(
name: "fk_tenant_branding_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "tenant_domains",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
host = table.Column(type: "citext", maxLength: 253, nullable: false),
domain_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
is_primary = table.Column(type: "boolean", nullable: false),
verification_token = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
verified_at = table.Column(type: "timestamp with time zone", nullable: true),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_tenant_domains", x => x.id);
table.UniqueConstraint("ak_tenant_domains_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_tenant_domains_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "tenant_settings",
columns: table => new
{
tenant_id = table.Column(type: "uuid", nullable: false),
feature_flags = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
admin_feature_flags = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
public_config = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_tenant_settings", x => x.tenant_id);
table.ForeignKey(
name: "fk_tenant_settings_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "content_nodes",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
entry_id = table.Column(type: "uuid", nullable: false),
region_id = table.Column(type: "uuid", nullable: true),
parent_id = table.Column(type: "uuid", nullable: true),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
node_key = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
name = table.Column(type: "character varying(300)", maxLength: 300, nullable: false),
node_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
marker_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
marker_config = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
path = table.Column(type: "ltree", nullable: true),
depth = table.Column(type: "integer", nullable: false),
sort_order = table.Column(type: "integer", nullable: false),
is_active = table.Column(type: "boolean", nullable: false),
is_selectable = table.Column(type: "boolean", nullable: false),
is_leaf = table.Column(type: "boolean", nullable: false),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
created_by = table.Column(type: "uuid", nullable: true),
updated_by = table.Column(type: "uuid", nullable: true),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_content_nodes", x => x.id);
table.UniqueConstraint("ak_content_nodes_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_content_nodes_depth", "depth >= 0");
table.ForeignKey(
name: "fk_content_nodes_content_entries_tenant_id_entry_id",
columns: x => new { x.tenant_id, x.entry_id },
principalTable: "content_entries",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_content_nodes_content_nodes_tenant_id_parent_id",
columns: x => new { x.tenant_id, x.parent_id },
principalTable: "content_nodes",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_content_nodes_regions_tenant_id_region_id",
columns: x => new { x.tenant_id, x.region_id },
principalTable: "regions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_content_nodes_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_content_nodes_users_created_by",
column: x => x.created_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "fk_content_nodes_users_updated_by",
column: x => x.updated_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "question_collections",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column(type: "uuid", nullable: true),
entry_id = table.Column(type: "uuid", nullable: true),
node_id = table.Column(type: "uuid", nullable: true),
subject_id = table.Column(type: "uuid", nullable: true),
category_id = table.Column(type: "uuid", nullable: true),
question_bank_id = table.Column(type: "uuid", nullable: true),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
name = table.Column(type: "character varying(300)", maxLength: 300, nullable: false),
collection_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
source_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
filters = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
question_count = table.Column(type: "integer", nullable: false),
total_score = table.Column(type: "numeric(8,2)", precision: 8, scale: 2, nullable: true),
duration_minutes = table.Column(type: "integer", nullable: true),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
sort_order = table.Column(type: "integer", nullable: false),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
created_by = table.Column(type: "uuid", nullable: true),
updated_by = table.Column(type: "uuid", nullable: true),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_question_collections", x => x.id);
table.UniqueConstraint("ak_question_collections_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_question_collections_duration", "duration_minutes is null or duration_minutes > 0");
table.CheckConstraint("ck_question_collections_question_count", "question_count >= 0");
table.ForeignKey(
name: "fk_question_collections_categories_tenant_id_category_id",
columns: x => new { x.tenant_id, x.category_id },
principalTable: "categories",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_question_collections_content_entries_tenant_id_entry_id",
columns: x => new { x.tenant_id, x.entry_id },
principalTable: "content_entries",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_question_collections_content_nodes_tenant_id_node_id",
columns: x => new { x.tenant_id, x.node_id },
principalTable: "content_nodes",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_question_collections_question_banks_tenant_id_question_bank~",
columns: x => new { x.tenant_id, x.question_bank_id },
principalTable: "question_banks",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_question_collections_regions_tenant_id_region_id",
columns: x => new { x.tenant_id, x.region_id },
principalTable: "regions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_question_collections_subjects_tenant_id_subject_id",
columns: x => new { x.tenant_id, x.subject_id },
principalTable: "subjects",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_question_collections_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_question_collections_users_created_by",
column: x => x.created_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "fk_question_collections_users_updated_by",
column: x => x.updated_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "practice_blueprints",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column(type: "uuid", nullable: true),
entry_id = table.Column(type: "uuid", nullable: true),
node_id = table.Column(type: "uuid", nullable: true),
collection_id = table.Column(type: "uuid", nullable: true),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
name = table.Column(type: "character varying(300)", maxLength: 300, nullable: false),
mode = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
assembly_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
question_limit = table.Column(type: "integer", nullable: true),
duration_minutes = table.Column(type: "integer", nullable: true),
total_score = table.Column(type: "numeric(8,2)", precision: 8, scale: 2, nullable: true),
pass_score = table.Column(type: "numeric(8,2)", precision: 8, scale: 2, nullable: true),
sections = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
rules = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
sort_order = table.Column(type: "integer", nullable: false),
created_by = table.Column(type: "uuid", nullable: true),
updated_by = table.Column(type: "uuid", nullable: true),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_practice_blueprints", x => x.id);
table.UniqueConstraint("ak_practice_blueprints_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_practice_blueprints_duration", "duration_minutes is null or duration_minutes > 0");
table.CheckConstraint("ck_practice_blueprints_question_limit", "question_limit is null or question_limit > 0");
table.ForeignKey(
name: "fk_practice_blueprints_content_entries_tenant_id_entry_id",
columns: x => new { x.tenant_id, x.entry_id },
principalTable: "content_entries",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_practice_blueprints_content_nodes_tenant_id_node_id",
columns: x => new { x.tenant_id, x.node_id },
principalTable: "content_nodes",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_practice_blueprints_question_collections_tenant_id_collecti~",
columns: x => new { x.tenant_id, x.collection_id },
principalTable: "question_collections",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_practice_blueprints_regions_tenant_id_region_id",
columns: x => new { x.tenant_id, x.region_id },
principalTable: "regions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_practice_blueprints_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_practice_blueprints_users_created_by",
column: x => x.created_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "fk_practice_blueprints_users_updated_by",
column: x => x.updated_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "question_collection_items",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
collection_id = table.Column(type: "uuid", nullable: false),
question_id = table.Column(type: "uuid", nullable: false),
section_key = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
sort_order = table.Column(type: "integer", nullable: false),
score = table.Column(type: "numeric(8,2)", precision: 8, scale: 2, nullable: true),
required = table.Column(type: "boolean", nullable: false),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
tenant_id = table.Column(type: "uuid", nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_question_collection_items", x => x.id);
table.UniqueConstraint("ak_question_collection_items_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_question_collection_items_question_collections_tenant_id_co~",
columns: x => new { x.tenant_id, x.collection_id },
principalTable: "question_collections",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_question_collection_items_questions_tenant_id_question_id",
columns: x => new { x.tenant_id, x.question_id },
principalTable: "questions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_question_collection_items_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_questions_tenant_id_content_node_id",
table: "questions",
columns: new[] { "tenant_id", "content_node_id" });
migrationBuilder.CreateIndex(
name: "ix_questions_tenant_id_entry_id",
table: "questions",
columns: new[] { "tenant_id", "entry_id" });
migrationBuilder.CreateIndex(
name: "ix_questions_tenant_id_primary_collection_id",
table: "questions",
columns: new[] { "tenant_id", "primary_collection_id" });
migrationBuilder.CreateIndex(
name: "ix_practice_sessions_tenant_id_blueprint_id",
table: "practice_sessions",
columns: new[] { "tenant_id", "blueprint_id" });
migrationBuilder.CreateIndex(
name: "ix_practice_sessions_tenant_id_collection_id",
table: "practice_sessions",
columns: new[] { "tenant_id", "collection_id" });
migrationBuilder.CreateIndex(
name: "ix_practice_sessions_tenant_id_content_node_id",
table: "practice_sessions",
columns: new[] { "tenant_id", "content_node_id" });
migrationBuilder.CreateIndex(
name: "ix_practice_sessions_tenant_id_entry_id",
table: "practice_sessions",
columns: new[] { "tenant_id", "entry_id" });
migrationBuilder.CreateIndex(
name: "ix_content_entries_created_by",
table: "content_entries",
column: "created_by");
migrationBuilder.CreateIndex(
name: "ix_content_entries_tenant_id_entry_key",
table: "content_entries",
columns: new[] { "tenant_id", "entry_key" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_content_entries_tenant_id_legacy_id",
table: "content_entries",
columns: new[] { "tenant_id", "legacy_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_content_entries_tenant_id_region_id_entry_type_is_active_so~",
table: "content_entries",
columns: new[] { "tenant_id", "region_id", "entry_type", "is_active", "sort_order" });
migrationBuilder.CreateIndex(
name: "ix_content_entries_updated_by",
table: "content_entries",
column: "updated_by");
migrationBuilder.CreateIndex(
name: "ix_content_nodes_created_by",
table: "content_nodes",
column: "created_by");
migrationBuilder.CreateIndex(
name: "ix_content_nodes_path",
table: "content_nodes",
column: "path")
.Annotation("Npgsql:IndexMethod", "gist");
migrationBuilder.CreateIndex(
name: "ix_content_nodes_tenant_id_entry_id_node_key",
table: "content_nodes",
columns: new[] { "tenant_id", "entry_id", "node_key" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_content_nodes_tenant_id_entry_id_parent_id_sort_order",
table: "content_nodes",
columns: new[] { "tenant_id", "entry_id", "parent_id", "sort_order" });
migrationBuilder.CreateIndex(
name: "ix_content_nodes_tenant_id_legacy_id",
table: "content_nodes",
columns: new[] { "tenant_id", "legacy_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_content_nodes_tenant_id_marker_type",
table: "content_nodes",
columns: new[] { "tenant_id", "marker_type" },
filter: "marker_type is not null");
migrationBuilder.CreateIndex(
name: "ix_content_nodes_tenant_id_parent_id",
table: "content_nodes",
columns: new[] { "tenant_id", "parent_id" });
migrationBuilder.CreateIndex(
name: "ix_content_nodes_tenant_id_region_id",
table: "content_nodes",
columns: new[] { "tenant_id", "region_id" });
migrationBuilder.CreateIndex(
name: "ix_content_nodes_updated_by",
table: "content_nodes",
column: "updated_by");
migrationBuilder.CreateIndex(
name: "ix_practice_blueprints_created_by",
table: "practice_blueprints",
column: "created_by");
migrationBuilder.CreateIndex(
name: "ix_practice_blueprints_tenant_id_collection_id",
table: "practice_blueprints",
columns: new[] { "tenant_id", "collection_id" });
migrationBuilder.CreateIndex(
name: "ix_practice_blueprints_tenant_id_entry_id",
table: "practice_blueprints",
columns: new[] { "tenant_id", "entry_id" });
migrationBuilder.CreateIndex(
name: "ix_practice_blueprints_tenant_id_legacy_id",
table: "practice_blueprints",
columns: new[] { "tenant_id", "legacy_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_practice_blueprints_tenant_id_node_id_collection_id_mode_st~",
table: "practice_blueprints",
columns: new[] { "tenant_id", "node_id", "collection_id", "mode", "status", "sort_order" });
migrationBuilder.CreateIndex(
name: "ix_practice_blueprints_tenant_id_region_id",
table: "practice_blueprints",
columns: new[] { "tenant_id", "region_id" });
migrationBuilder.CreateIndex(
name: "ix_practice_blueprints_updated_by",
table: "practice_blueprints",
column: "updated_by");
migrationBuilder.CreateIndex(
name: "ix_question_collection_items_tenant_id_collection_id_question_~",
table: "question_collection_items",
columns: new[] { "tenant_id", "collection_id", "question_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_question_collection_items_tenant_id_collection_id_section_k~",
table: "question_collection_items",
columns: new[] { "tenant_id", "collection_id", "section_key", "sort_order" });
migrationBuilder.CreateIndex(
name: "ix_question_collection_items_tenant_id_question_id",
table: "question_collection_items",
columns: new[] { "tenant_id", "question_id" });
migrationBuilder.CreateIndex(
name: "ix_question_collections_created_by",
table: "question_collections",
column: "created_by");
migrationBuilder.CreateIndex(
name: "ix_question_collections_tenant_id_category_id",
table: "question_collections",
columns: new[] { "tenant_id", "category_id" });
migrationBuilder.CreateIndex(
name: "ix_question_collections_tenant_id_entry_id",
table: "question_collections",
columns: new[] { "tenant_id", "entry_id" });
migrationBuilder.CreateIndex(
name: "ix_question_collections_tenant_id_legacy_id",
table: "question_collections",
columns: new[] { "tenant_id", "legacy_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_question_collections_tenant_id_node_id_status_sort_order",
table: "question_collections",
columns: new[] { "tenant_id", "node_id", "status", "sort_order" });
migrationBuilder.CreateIndex(
name: "ix_question_collections_tenant_id_question_bank_id",
table: "question_collections",
columns: new[] { "tenant_id", "question_bank_id" });
migrationBuilder.CreateIndex(
name: "ix_question_collections_tenant_id_region_id",
table: "question_collections",
columns: new[] { "tenant_id", "region_id" });
migrationBuilder.CreateIndex(
name: "ix_question_collections_tenant_id_subject_id",
table: "question_collections",
columns: new[] { "tenant_id", "subject_id" });
migrationBuilder.CreateIndex(
name: "ix_question_collections_updated_by",
table: "question_collections",
column: "updated_by");
migrationBuilder.CreateIndex(
name: "ix_tenant_domains_host",
table: "tenant_domains",
column: "host",
unique: true);
migrationBuilder.CreateIndex(
name: "ix_tenant_domains_tenant_id_is_primary",
table: "tenant_domains",
columns: new[] { "tenant_id", "is_primary" },
unique: true,
filter: "is_primary");
migrationBuilder.AddForeignKey(
name: "fk_practice_sessions_content_entries_tenant_id_entry_id",
table: "practice_sessions",
columns: new[] { "tenant_id", "entry_id" },
principalTable: "content_entries",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "fk_practice_sessions_content_nodes_tenant_id_content_node_id",
table: "practice_sessions",
columns: new[] { "tenant_id", "content_node_id" },
principalTable: "content_nodes",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "fk_practice_sessions_practice_blueprints_tenant_id_blueprint_id",
table: "practice_sessions",
columns: new[] { "tenant_id", "blueprint_id" },
principalTable: "practice_blueprints",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "fk_practice_sessions_question_collections_tenant_id_collection~",
table: "practice_sessions",
columns: new[] { "tenant_id", "collection_id" },
principalTable: "question_collections",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "fk_questions_content_entries_tenant_id_entry_id",
table: "questions",
columns: new[] { "tenant_id", "entry_id" },
principalTable: "content_entries",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "fk_questions_content_nodes_tenant_id_content_node_id",
table: "questions",
columns: new[] { "tenant_id", "content_node_id" },
principalTable: "content_nodes",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "fk_questions_question_collections_tenant_id_primary_collection~",
table: "questions",
columns: new[] { "tenant_id", "primary_collection_id" },
principalTable: "question_collections",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
}
///
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "fk_practice_sessions_content_entries_tenant_id_entry_id",
table: "practice_sessions");
migrationBuilder.DropForeignKey(
name: "fk_practice_sessions_content_nodes_tenant_id_content_node_id",
table: "practice_sessions");
migrationBuilder.DropForeignKey(
name: "fk_practice_sessions_practice_blueprints_tenant_id_blueprint_id",
table: "practice_sessions");
migrationBuilder.DropForeignKey(
name: "fk_practice_sessions_question_collections_tenant_id_collection~",
table: "practice_sessions");
migrationBuilder.DropForeignKey(
name: "fk_questions_content_entries_tenant_id_entry_id",
table: "questions");
migrationBuilder.DropForeignKey(
name: "fk_questions_content_nodes_tenant_id_content_node_id",
table: "questions");
migrationBuilder.DropForeignKey(
name: "fk_questions_question_collections_tenant_id_primary_collection~",
table: "questions");
migrationBuilder.DropTable(
name: "practice_blueprints");
migrationBuilder.DropTable(
name: "question_collection_items");
migrationBuilder.DropTable(
name: "tenant_branding");
migrationBuilder.DropTable(
name: "tenant_domains");
migrationBuilder.DropTable(
name: "tenant_settings");
migrationBuilder.DropTable(
name: "question_collections");
migrationBuilder.DropTable(
name: "content_nodes");
migrationBuilder.DropTable(
name: "content_entries");
migrationBuilder.DropIndex(
name: "ix_questions_tenant_id_content_node_id",
table: "questions");
migrationBuilder.DropIndex(
name: "ix_questions_tenant_id_entry_id",
table: "questions");
migrationBuilder.DropIndex(
name: "ix_questions_tenant_id_primary_collection_id",
table: "questions");
migrationBuilder.DropIndex(
name: "ix_practice_sessions_tenant_id_blueprint_id",
table: "practice_sessions");
migrationBuilder.DropIndex(
name: "ix_practice_sessions_tenant_id_collection_id",
table: "practice_sessions");
migrationBuilder.DropIndex(
name: "ix_practice_sessions_tenant_id_content_node_id",
table: "practice_sessions");
migrationBuilder.DropIndex(
name: "ix_practice_sessions_tenant_id_entry_id",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "content_node_id",
table: "questions");
migrationBuilder.DropColumn(
name: "entry_id",
table: "questions");
migrationBuilder.DropColumn(
name: "exam_markers",
table: "questions");
migrationBuilder.DropColumn(
name: "primary_collection_id",
table: "questions");
migrationBuilder.DropColumn(
name: "blueprint_id",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "collection_id",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "content_node_id",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "duration_minutes",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "entry_id",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "expires_at",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "question_count",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "question_ids",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "total_score",
table: "practice_sessions");
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:PostgresExtension:citext", ",,")
.OldAnnotation("Npgsql:PostgresExtension:citext", ",,")
.OldAnnotation("Npgsql:PostgresExtension:ltree", ",,");
}
}
}