1230 lines
69 KiB
C#
1230 lines
69 KiB
C#
using System;
|
|
using System.Text.Json;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace Tiku.Infrastructure.Persistence.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class InitialCore : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.AlterDatabase()
|
|
.Annotation("Npgsql:PostgresExtension:citext", ",,");
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "users",
|
|
columns: table => new
|
|
{
|
|
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
username = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
email = table.Column<string>(type: "citext", maxLength: 320, nullable: true),
|
|
phone = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
|
avatar_url = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true),
|
|
primary_role = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
score = table.Column<int>(type: "integer", nullable: false),
|
|
last_seen_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
legacy_password_hash = table.Column<string>(type: "character varying(512)", maxLength: 512, nullable: true),
|
|
password_migration_required = table.Column<bool>(type: "boolean", nullable: false),
|
|
raw_profile = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
slug = table.Column<string>(type: "citext", maxLength: 100, nullable: false),
|
|
name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
legal_name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
|
|
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
mode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
billing_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
owner_user_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
provider = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
provider_subject = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
|
|
union_id = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
|
|
open_id = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
|
|
phone = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
email = table.Column<string>(type: "citext", maxLength: 320, nullable: true),
|
|
secret_payload = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
mode = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
target_type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
target_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
started_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
finished_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
tenant_id = table.Column<Guid>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
user_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
practice_type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
target_legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
target_name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
|
|
progress = table.Column<int>(type: "integer", nullable: false),
|
|
color = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
last_access_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
last_practice_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
|
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
code = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
short_name = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
full_name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
|
|
icon = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true),
|
|
pinyin = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
|
|
sort_order = table.Column<int>(type: "integer", nullable: false),
|
|
is_hot = table.Column<bool>(type: "boolean", nullable: false),
|
|
is_active = table.Column<bool>(type: "boolean", nullable: false),
|
|
config = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
role = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
permissions = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
legacy_role = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
region_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
|
|
source_scope = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
region_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
|
type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
icon = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true),
|
|
color = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
text_color = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
description = table.Column<string>(type: "text", nullable: true),
|
|
route = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: true),
|
|
sort_order = table.Column<int>(type: "integer", nullable: false),
|
|
is_primary_school_module = table.Column<bool>(type: "boolean", nullable: false),
|
|
is_active = table.Column<bool>(type: "boolean", nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
region_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
module_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
parent_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
legacy_parent_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
legacy_module_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
|
|
path = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
|
|
sort_order = table.Column<int>(type: "integer", nullable: false),
|
|
is_active = table.Column<bool>(type: "boolean", nullable: false),
|
|
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
region_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
module_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
|
|
professional_exam_date = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true),
|
|
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
region_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
school_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
|
|
description = table.Column<string>(type: "text", nullable: true),
|
|
study_tips = table.Column<string>(type: "text", nullable: true),
|
|
sort_order = table.Column<int>(type: "integer", nullable: false),
|
|
is_active = table.Column<bool>(type: "boolean", nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
legacy_user_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
region_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
selected_school_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
selected_major_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
questions_answered_today = table.Column<int>(type: "integer", nullable: false),
|
|
mastered_words_count = table.Column<int>(type: "integer", nullable: false),
|
|
last_check_in_date = table.Column<DateOnly>(type: "date", nullable: true),
|
|
stats = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
progress = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
module_selections = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
recent_activities = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
region_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
module_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
school_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
major_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
node_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
|
|
type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
major_legacy_ids = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
|
|
icon = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true),
|
|
description = table.Column<string>(type: "text", nullable: true),
|
|
stats = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
|
sort_order = table.Column<int>(type: "integer", nullable: false),
|
|
is_active = table.Column<bool>(type: "boolean", nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
subject_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
node_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
|
|
category_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
|
sort_order = table.Column<int>(type: "integer", nullable: false),
|
|
svip_question_limit = table.Column<int>(type: "integer", nullable: true),
|
|
is_active = table.Column<bool>(type: "boolean", nullable: false),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
question_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
question_version_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
practice_session_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
legacy_question_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
legacy_category_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
selected_options = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
|
|
answer_text = table.Column<string>(type: "text", nullable: true),
|
|
is_correct = table.Column<bool>(type: "boolean", nullable: true),
|
|
answered_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
tenant_id = table.Column<Guid>(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<Guid>(type: "uuid", nullable: false),
|
|
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
question_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
source = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
question_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
version_no = table.Column<int>(type: "integer", nullable: false),
|
|
content = table.Column<string>(type: "text", nullable: true),
|
|
options = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
|
|
correct_option_index = table.Column<int>(type: "integer", nullable: true),
|
|
correct_option_indices = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
|
|
answer_text = table.Column<string>(type: "text", nullable: true),
|
|
explanation = table.Column<string>(type: "text", nullable: true),
|
|
sub_questions = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
|
|
code_lang = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
|
code_template = table.Column<string>(type: "text", nullable: true),
|
|
source_hash = table.Column<string>(type: "character varying(128)", maxLength: 128, nullable: true),
|
|
created_by = table.Column<Guid>(type: "uuid", nullable: true),
|
|
created_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
|
question_bank_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
subject_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
category_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
node_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
legacy_subject_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
legacy_category_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
legacy_node_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
|
type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
|
type_label = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
|
difficulty = table.Column<int>(type: "integer", nullable: true),
|
|
tags = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
|
|
media_url = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true),
|
|
has_video_explanation = table.Column<bool>(type: "boolean", nullable: false),
|
|
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
|
current_version_id = table.Column<Guid>(type: "uuid", nullable: true),
|
|
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
updated_at = table.Column<DateTimeOffset>(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<Guid>(type: "uuid", nullable: false),
|
|
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
question_id = table.Column<Guid>(type: "uuid", nullable: false),
|
|
wrong_count = table.Column<int>(type: "integer", nullable: false, defaultValue: 1),
|
|
last_wrong_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
|
resolved_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("pk_wrong_questions", x => new { x.tenant_id, x.user_id, x.question_id });
|
|
table.ForeignKey(
|
|
name: "fk_wrong_questions_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_wrong_questions_tenants_tenant_id",
|
|
column: x => x.tenant_id,
|
|
principalTable: "tenants",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
table.ForeignKey(
|
|
name: "fk_wrong_questions_users_user_id",
|
|
column: x => x.user_id,
|
|
principalTable: "users",
|
|
principalColumn: "id",
|
|
onDelete: ReferentialAction.Cascade);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_answer_records_tenant_id_legacy_id",
|
|
table: "answer_records",
|
|
columns: new[] { "tenant_id", "legacy_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_answer_records_tenant_id_question_id",
|
|
table: "answer_records",
|
|
columns: new[] { "tenant_id", "question_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_answer_records_tenant_id_question_id_question_version_id",
|
|
table: "answer_records",
|
|
columns: new[] { "tenant_id", "question_id", "question_version_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_answer_records_tenant_id_user_id_practice_session_id",
|
|
table: "answer_records",
|
|
columns: new[] { "tenant_id", "user_id", "practice_session_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_answer_records_user_id",
|
|
table: "answer_records",
|
|
column: "user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_categories_tenant_id_legacy_id",
|
|
table: "categories",
|
|
columns: new[] { "tenant_id", "legacy_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_categories_tenant_id_node_id",
|
|
table: "categories",
|
|
columns: new[] { "tenant_id", "node_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_categories_tenant_id_subject_id",
|
|
table: "categories",
|
|
columns: new[] { "tenant_id", "subject_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_favorite_questions_tenant_id_question_id",
|
|
table: "favorite_questions",
|
|
columns: new[] { "tenant_id", "question_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_favorite_questions_user_id",
|
|
table: "favorite_questions",
|
|
column: "user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_majors_tenant_id_legacy_id",
|
|
table: "majors",
|
|
columns: new[] { "tenant_id", "legacy_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_majors_tenant_id_region_id",
|
|
table: "majors",
|
|
columns: new[] { "tenant_id", "region_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_majors_tenant_id_school_id",
|
|
table: "majors",
|
|
columns: new[] { "tenant_id", "school_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_module_nodes_tenant_id_legacy_id",
|
|
table: "module_nodes",
|
|
columns: new[] { "tenant_id", "legacy_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_module_nodes_tenant_id_module_id",
|
|
table: "module_nodes",
|
|
columns: new[] { "tenant_id", "module_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_module_nodes_tenant_id_parent_id",
|
|
table: "module_nodes",
|
|
columns: new[] { "tenant_id", "parent_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_module_nodes_tenant_id_region_id",
|
|
table: "module_nodes",
|
|
columns: new[] { "tenant_id", "region_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_practice_sessions_tenant_id_user_id_started_at",
|
|
table: "practice_sessions",
|
|
columns: new[] { "tenant_id", "user_id", "started_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_practice_sessions_user_id",
|
|
table: "practice_sessions",
|
|
column: "user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_question_banks_tenant_id_region_id",
|
|
table: "question_banks",
|
|
columns: new[] { "tenant_id", "region_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_question_versions_created_by",
|
|
table: "question_versions",
|
|
column: "created_by");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_question_versions_question_id_version_no",
|
|
table: "question_versions",
|
|
columns: new[] { "question_id", "version_no" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_questions_tenant_id_category_id",
|
|
table: "questions",
|
|
columns: new[] { "tenant_id", "category_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_questions_tenant_id_id_current_version_id",
|
|
table: "questions",
|
|
columns: new[] { "tenant_id", "id", "current_version_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_questions_tenant_id_legacy_id",
|
|
table: "questions",
|
|
columns: new[] { "tenant_id", "legacy_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_questions_tenant_id_node_id",
|
|
table: "questions",
|
|
columns: new[] { "tenant_id", "node_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_questions_tenant_id_question_bank_id",
|
|
table: "questions",
|
|
columns: new[] { "tenant_id", "question_bank_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_questions_tenant_id_subject_id",
|
|
table: "questions",
|
|
columns: new[] { "tenant_id", "subject_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_recent_practices_tenant_id_legacy_id",
|
|
table: "recent_practices",
|
|
columns: new[] { "tenant_id", "legacy_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_recent_practices_tenant_id_user_id_last_access_at",
|
|
table: "recent_practices",
|
|
columns: new[] { "tenant_id", "user_id", "last_access_at" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_recent_practices_user_id",
|
|
table: "recent_practices",
|
|
column: "user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_region_modules_tenant_id_legacy_id",
|
|
table: "region_modules",
|
|
columns: new[] { "tenant_id", "legacy_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_region_modules_tenant_id_region_id",
|
|
table: "region_modules",
|
|
columns: new[] { "tenant_id", "region_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_regions_tenant_id_legacy_id",
|
|
table: "regions",
|
|
columns: new[] { "tenant_id", "legacy_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_schools_tenant_id_legacy_id",
|
|
table: "schools",
|
|
columns: new[] { "tenant_id", "legacy_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_schools_tenant_id_module_id",
|
|
table: "schools",
|
|
columns: new[] { "tenant_id", "module_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_schools_tenant_id_region_id",
|
|
table: "schools",
|
|
columns: new[] { "tenant_id", "region_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_student_profiles_tenant_id_region_id",
|
|
table: "student_profiles",
|
|
columns: new[] { "tenant_id", "region_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_student_profiles_tenant_id_selected_major_id",
|
|
table: "student_profiles",
|
|
columns: new[] { "tenant_id", "selected_major_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_student_profiles_tenant_id_selected_school_id",
|
|
table: "student_profiles",
|
|
columns: new[] { "tenant_id", "selected_school_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_student_profiles_tenant_id_user_id",
|
|
table: "student_profiles",
|
|
columns: new[] { "tenant_id", "user_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_student_profiles_user_id",
|
|
table: "student_profiles",
|
|
column: "user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_subjects_tenant_id_legacy_id",
|
|
table: "subjects",
|
|
columns: new[] { "tenant_id", "legacy_id" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_subjects_tenant_id_major_id",
|
|
table: "subjects",
|
|
columns: new[] { "tenant_id", "major_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_subjects_tenant_id_module_id",
|
|
table: "subjects",
|
|
columns: new[] { "tenant_id", "module_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_subjects_tenant_id_node_id",
|
|
table: "subjects",
|
|
columns: new[] { "tenant_id", "node_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_subjects_tenant_id_region_id",
|
|
table: "subjects",
|
|
columns: new[] { "tenant_id", "region_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_subjects_tenant_id_school_id",
|
|
table: "subjects",
|
|
columns: new[] { "tenant_id", "school_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_tenant_memberships_tenant_id_user_id_role",
|
|
table: "tenant_memberships",
|
|
columns: new[] { "tenant_id", "user_id", "role" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_tenant_memberships_user_id",
|
|
table: "tenant_memberships",
|
|
column: "user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_tenants_legacy_id",
|
|
table: "tenants",
|
|
column: "legacy_id",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_tenants_owner_user_id",
|
|
table: "tenants",
|
|
column: "owner_user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_tenants_slug",
|
|
table: "tenants",
|
|
column: "slug",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_user_identities_provider_provider_subject",
|
|
table: "user_identities",
|
|
columns: new[] { "provider", "provider_subject" },
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_user_identities_user_id",
|
|
table: "user_identities",
|
|
column: "user_id");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_users_email",
|
|
table: "users",
|
|
column: "email",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_users_legacy_id",
|
|
table: "users",
|
|
column: "legacy_id",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_users_phone",
|
|
table: "users",
|
|
column: "phone",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_users_username",
|
|
table: "users",
|
|
column: "username",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_wrong_questions_tenant_id_question_id",
|
|
table: "wrong_questions",
|
|
columns: new[] { "tenant_id", "question_id" });
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "ix_wrong_questions_user_id",
|
|
table: "wrong_questions",
|
|
column: "user_id");
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "fk_answer_records_question_versions_tenant_id_question_id_ques~",
|
|
table: "answer_records",
|
|
columns: new[] { "tenant_id", "question_id", "question_version_id" },
|
|
principalTable: "question_versions",
|
|
principalColumns: new[] { "tenant_id", "question_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "fk_answer_records_questions_tenant_id_question_id",
|
|
table: "answer_records",
|
|
columns: new[] { "tenant_id", "question_id" },
|
|
principalTable: "questions",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Restrict);
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "fk_favorite_questions_questions_tenant_id_question_id",
|
|
table: "favorite_questions",
|
|
columns: new[] { "tenant_id", "question_id" },
|
|
principalTable: "questions",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Cascade);
|
|
|
|
migrationBuilder.AddForeignKey(
|
|
name: "fk_question_versions_questions_tenant_id_question_id",
|
|
table: "question_versions",
|
|
columns: new[] { "tenant_id", "question_id" },
|
|
principalTable: "questions",
|
|
principalColumns: new[] { "tenant_id", "id" },
|
|
onDelete: ReferentialAction.Cascade);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropForeignKey(
|
|
name: "fk_questions_question_versions_tenant_id_id_current_version_id",
|
|
table: "questions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "answer_records");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "favorite_questions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "recent_practices");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "student_profiles");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "tenant_memberships");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "user_identities");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "wrong_questions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "practice_sessions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "question_versions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "questions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "categories");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "question_banks");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "subjects");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "majors");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "module_nodes");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "schools");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "region_modules");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "regions");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "tenants");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "users");
|
|
}
|
|
}
|
|
}
|