using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Tiku.Infrastructure.Persistence.Migrations
{
///
public partial class InitialCore : Migration
{
///
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterDatabase()
.Annotation("Npgsql:PostgresExtension:citext", ",,");
migrationBuilder.CreateTable(
name: "users",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
username = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
email = table.Column(type: "citext", maxLength: 320, nullable: true),
phone = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: true),
avatar_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
primary_role = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
score = table.Column(type: "integer", nullable: false),
last_seen_at = table.Column(type: "timestamp with time zone", nullable: true),
legacy_password_hash = table.Column(type: "character varying(512)", maxLength: 512, nullable: true),
password_migration_required = table.Column(type: "boolean", nullable: false),
raw_profile = 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_users", x => x.id);
});
migrationBuilder.CreateTable(
name: "tenants",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
slug = table.Column(type: "citext", maxLength: 100, nullable: false),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
legal_name = table.Column(type: "character varying(300)", maxLength: 300, nullable: true),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
mode = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
billing_status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
owner_user_id = table.Column(type: "uuid", nullable: true),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
metadata = 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_tenants", x => x.id);
table.ForeignKey(
name: "fk_tenants_users_owner_user_id",
column: x => x.owner_user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "user_identities",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column(type: "uuid", nullable: false),
provider = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
provider_subject = table.Column(type: "character varying(255)", maxLength: 255, nullable: false),
union_id = table.Column(type: "character varying(255)", maxLength: 255, nullable: true),
open_id = table.Column(type: "character varying(255)", maxLength: 255, nullable: true),
phone = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
email = table.Column(type: "citext", maxLength: 320, nullable: true),
secret_payload = 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_user_identities", x => x.id);
table.ForeignKey(
name: "fk_user_identities_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "practice_sessions",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column(type: "uuid", nullable: false),
mode = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
target_type = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
target_id = table.Column(type: "uuid", nullable: true),
started_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
finished_at = table.Column(type: "timestamp with time zone", nullable: true),
metadata = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
tenant_id = table.Column(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_practice_sessions", x => x.id);
table.UniqueConstraint("ak_practice_sessions_tenant_id_id", x => new { x.tenant_id, x.id });
table.UniqueConstraint("ak_practice_sessions_tenant_id_user_id_id", x => new { x.tenant_id, x.user_id, x.id });
table.ForeignKey(
name: "fk_practice_sessions_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_practice_sessions_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "recent_practices",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column(type: "uuid", nullable: true),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
practice_type = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
target_legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
target_name = table.Column(type: "character varying(300)", maxLength: 300, nullable: true),
progress = table.Column(type: "integer", nullable: false),
color = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
last_access_at = table.Column(type: "timestamp with time zone", nullable: true),
last_practice_at = table.Column(type: "timestamp with time zone", nullable: true),
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_recent_practices", x => x.id);
table.UniqueConstraint("ak_recent_practices_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_recent_practices_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_recent_practices_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "regions",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
code = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
short_name = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
full_name = table.Column(type: "character varying(300)", maxLength: 300, nullable: true),
icon = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
pinyin = table.Column(type: "character varying(255)", maxLength: 255, nullable: true),
sort_order = table.Column(type: "integer", nullable: false),
is_hot = table.Column(type: "boolean", nullable: false),
is_active = table.Column(type: "boolean", nullable: false),
config = 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_regions", x => x.id);
table.UniqueConstraint("ak_regions_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_regions_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "tenant_memberships",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column(type: "uuid", nullable: false),
role = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
permissions = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
legacy_role = table.Column(type: "character varying(50)", maxLength: 50, 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_memberships", x => x.id);
table.UniqueConstraint("ak_tenant_memberships_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_tenant_memberships_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_tenant_memberships_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "question_banks",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column(type: "uuid", nullable: true),
name = table.Column(type: "character varying(300)", maxLength: 300, nullable: false),
source_scope = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
status = table.Column(type: "character varying(32)", maxLength: 32, 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_banks", x => x.id);
table.UniqueConstraint("ak_question_banks_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_question_banks_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_banks_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "region_modules",
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),
name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false),
type = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
icon = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
color = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
text_color = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
description = table.Column(type: "text", nullable: true),
route = table.Column(type: "character varying(500)", maxLength: 500, nullable: true),
sort_order = table.Column(type: "integer", nullable: false),
is_primary_school_module = table.Column(type: "boolean", nullable: false),
is_active = table.Column(type: "boolean", nullable: false),
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_region_modules", x => x.id);
table.UniqueConstraint("ak_region_modules_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_region_modules_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_region_modules_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "module_nodes",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column(type: "uuid", nullable: true),
module_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),
legacy_parent_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
legacy_module_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
name = table.Column(type: "character varying(300)", maxLength: 300, nullable: false),
path = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true),
sort_order = table.Column(type: "integer", nullable: false),
is_active = 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_module_nodes", x => x.id);
table.UniqueConstraint("ak_module_nodes_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_module_nodes_module_nodes_tenant_id_parent_id",
columns: x => new { x.tenant_id, x.parent_id },
principalTable: "module_nodes",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_module_nodes_region_modules_tenant_id_module_id",
columns: x => new { x.tenant_id, x.module_id },
principalTable: "region_modules",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_module_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_module_nodes_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "schools",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column(type: "uuid", nullable: true),
module_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),
professional_exam_date = table.Column(type: "character varying(255)", maxLength: 255, nullable: true),
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_schools", x => x.id);
table.UniqueConstraint("ak_schools_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_schools_region_modules_tenant_id_module_id",
columns: x => new { x.tenant_id, x.module_id },
principalTable: "region_modules",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_schools_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_schools_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "majors",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column(type: "uuid", nullable: true),
school_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),
description = table.Column(type: "text", nullable: true),
study_tips = table.Column(type: "text", nullable: true),
sort_order = table.Column(type: "integer", nullable: false),
is_active = table.Column(type: "boolean", nullable: false),
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_majors", x => x.id);
table.UniqueConstraint("ak_majors_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_majors_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_majors_schools_tenant_id_school_id",
columns: x => new { x.tenant_id, x.school_id },
principalTable: "schools",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_majors_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "student_profiles",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column(type: "uuid", nullable: false),
legacy_user_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
region_id = table.Column(type: "uuid", nullable: true),
selected_school_id = table.Column(type: "uuid", nullable: true),
selected_major_id = table.Column(type: "uuid", nullable: true),
questions_answered_today = table.Column(type: "integer", nullable: false),
mastered_words_count = table.Column(type: "integer", nullable: false),
last_check_in_date = table.Column(type: "date", nullable: true),
stats = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
progress = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
module_selections = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
recent_activities = 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_student_profiles", x => x.id);
table.UniqueConstraint("ak_student_profiles_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_student_profiles_majors_tenant_id_selected_major_id",
columns: x => new { x.tenant_id, x.selected_major_id },
principalTable: "majors",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_student_profiles_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_student_profiles_schools_tenant_id_selected_school_id",
columns: x => new { x.tenant_id, x.selected_school_id },
principalTable: "schools",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_student_profiles_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_student_profiles_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "subjects",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
region_id = table.Column(type: "uuid", nullable: true),
module_id = table.Column(type: "uuid", nullable: true),
school_id = table.Column(type: "uuid", nullable: true),
major_id = table.Column(type: "uuid", nullable: true),
node_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),
type = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
major_legacy_ids = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
icon = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
description = table.Column(type: "text", nullable: true),
stats = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
sort_order = table.Column(type: "integer", nullable: false),
is_active = table.Column(type: "boolean", nullable: false),
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_subjects", x => x.id);
table.UniqueConstraint("ak_subjects_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_subjects_majors_tenant_id_major_id",
columns: x => new { x.tenant_id, x.major_id },
principalTable: "majors",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_subjects_module_nodes_tenant_id_node_id",
columns: x => new { x.tenant_id, x.node_id },
principalTable: "module_nodes",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_subjects_region_modules_tenant_id_module_id",
columns: x => new { x.tenant_id, x.module_id },
principalTable: "region_modules",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_subjects_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_subjects_schools_tenant_id_school_id",
columns: x => new { x.tenant_id, x.school_id },
principalTable: "schools",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_subjects_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "categories",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
subject_id = table.Column(type: "uuid", nullable: true),
node_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),
category_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: true),
sort_order = table.Column(type: "integer", nullable: false),
svip_question_limit = table.Column(type: "integer", nullable: true),
is_active = table.Column(type: "boolean", nullable: false),
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_categories", x => x.id);
table.UniqueConstraint("ak_categories_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_categories_module_nodes_tenant_id_node_id",
columns: x => new { x.tenant_id, x.node_id },
principalTable: "module_nodes",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_categories_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_categories_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "answer_records",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column(type: "uuid", nullable: false),
question_id = table.Column(type: "uuid", nullable: true),
question_version_id = table.Column(type: "uuid", nullable: true),
practice_session_id = table.Column(type: "uuid", nullable: true),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
legacy_question_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
legacy_category_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
selected_options = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
answer_text = table.Column(type: "text", nullable: true),
is_correct = table.Column(type: "boolean", nullable: true),
answered_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
tenant_id = table.Column(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_answer_records", x => x.id);
table.UniqueConstraint("ak_answer_records_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_answer_records_version_requires_question", "question_version_id is null or question_id is not null");
table.ForeignKey(
name: "fk_answer_records_practice_sessions_tenant_id_user_id_practice~",
columns: x => new { x.tenant_id, x.user_id, x.practice_session_id },
principalTable: "practice_sessions",
principalColumns: new[] { "tenant_id", "user_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_answer_records_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_answer_records_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "favorite_questions",
columns: table => new
{
tenant_id = table.Column(type: "uuid", nullable: false),
user_id = table.Column(type: "uuid", nullable: false),
question_id = table.Column(type: "uuid", nullable: false),
source = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_favorite_questions", x => new { x.tenant_id, x.user_id, x.question_id });
table.ForeignKey(
name: "fk_favorite_questions_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_favorite_questions_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "question_versions",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
tenant_id = table.Column(type: "uuid", nullable: false),
question_id = table.Column(type: "uuid", nullable: false),
version_no = table.Column(type: "integer", nullable: false),
content = table.Column(type: "text", nullable: true),
options = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
correct_option_index = table.Column(type: "integer", nullable: true),
correct_option_indices = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
answer_text = table.Column(type: "text", nullable: true),
explanation = table.Column(type: "text", nullable: true),
sub_questions = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
code_lang = table.Column(type: "character varying(50)", maxLength: 50, nullable: true),
code_template = table.Column(type: "text", nullable: true),
source_hash = table.Column(type: "character varying(128)", maxLength: 128, nullable: true),
created_by = table.Column(type: "uuid", nullable: true),
created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
},
constraints: table =>
{
table.PrimaryKey("pk_question_versions", x => x.id);
table.UniqueConstraint("ak_question_versions_tenant_id_id", x => new { x.tenant_id, x.id });
table.UniqueConstraint("ak_question_versions_tenant_id_question_id_id", x => new { x.tenant_id, x.question_id, x.id });
table.ForeignKey(
name: "fk_question_versions_users_created_by",
column: x => x.created_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "questions",
columns: table => new
{
id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
question_bank_id = table.Column(type: "uuid", nullable: true),
subject_id = table.Column(type: "uuid", nullable: true),
category_id = table.Column(type: "uuid", nullable: true),
node_id = table.Column(type: "uuid", nullable: true),
legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
legacy_subject_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
legacy_category_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
legacy_node_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true),
type = table.Column(type: "character varying(50)", maxLength: 50, nullable: false),
type_label = table.Column(type: "character varying(100)", maxLength: 100, nullable: true),
difficulty = table.Column(type: "integer", nullable: true),
tags = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
media_url = table.Column(type: "character varying(2048)", maxLength: 2048, nullable: true),
has_video_explanation = table.Column(type: "boolean", nullable: false),
status = table.Column(type: "character varying(32)", maxLength: 32, nullable: false),
current_version_id = 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_questions", x => x.id);
table.UniqueConstraint("ak_questions_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_questions_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_questions_module_nodes_tenant_id_node_id",
columns: x => new { x.tenant_id, x.node_id },
principalTable: "module_nodes",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_questions_question_banks_tenant_id_question_bank_id",
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_questions_question_versions_tenant_id_id_current_version_id",
columns: x => new { x.tenant_id, x.id, x.current_version_id },
principalTable: "question_versions",
principalColumns: new[] { "tenant_id", "question_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_questions_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_questions_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "wrong_questions",
columns: table => new
{
tenant_id = table.Column(type: "uuid", nullable: false),
user_id = table.Column(type: "uuid", nullable: false),
question_id = table.Column(type: "uuid", nullable: false),
wrong_count = table.Column(type: "integer", nullable: false, defaultValue: 1),
last_wrong_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
resolved_at = table.Column