forked from gongxuegit/tiku-backend.net
feat: add vocabulary and handbook persistence
This commit is contained in:
4505
Tiku.Infrastructure/Persistence/Migrations/20260725210815_AddVocabularyAndHandbookPersistence.Designer.cs
generated
Normal file
4505
Tiku.Infrastructure/Persistence/Migrations/20260725210815_AddVocabularyAndHandbookPersistence.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,648 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Tiku.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddVocabularyAndHandbookPersistence : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "handbook_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),
|
||||
school_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
major_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
entry_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
content_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),
|
||||
icon = table.Column<string>(type: "character varying(2048)", maxLength: 2048, nullable: true),
|
||||
color = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
||||
description = table.Column<string>(type: "text", nullable: true),
|
||||
major_legacy_ids = 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),
|
||||
source_hash = table.Column<string>(type: "character varying(128)", maxLength: 128, 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_handbook_subjects", x => x.id);
|
||||
table.UniqueConstraint("ak_handbook_subjects_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.ForeignKey(
|
||||
name: "fk_handbook_subjects_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_handbook_subjects_content_nodes_tenant_id_content_node_id",
|
||||
columns: x => new { x.tenant_id, x.content_node_id },
|
||||
principalTable: "content_nodes",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_handbook_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_handbook_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_handbook_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_handbook_subjects_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "question_type_groups",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
subject_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
||||
display_name = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
||||
types = 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_question_type_groups", x => x.id);
|
||||
table.UniqueConstraint("ak_question_type_groups_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.ForeignKey(
|
||||
name: "fk_question_type_groups_subjects_tenant_id_subject_id",
|
||||
columns: x => new { x.tenant_id, x.subject_id },
|
||||
principalTable: "subjects",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_question_type_groups_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "subject_shares",
|
||||
columns: table => new
|
||||
{
|
||||
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
source_subject_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
target_subject_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
legacy_id = table.Column<string>(type: "text", nullable: true),
|
||||
legacy_source_subject_id = table.Column<string>(type: "text", nullable: true),
|
||||
legacy_target_subject_id = table.Column<string>(type: "text", nullable: true),
|
||||
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)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_subject_shares", x => new { x.tenant_id, x.source_subject_id, x.target_subject_id });
|
||||
table.ForeignKey(
|
||||
name: "fk_subject_shares_subjects_tenant_id_source_subject_id",
|
||||
columns: x => new { x.tenant_id, x.source_subject_id },
|
||||
principalTable: "subjects",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_subject_shares_subjects_tenant_id_target_subject_id",
|
||||
columns: x => new { x.tenant_id, x.target_subject_id },
|
||||
principalTable: "subjects",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_subject_shares_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "vocabulary_units",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
region_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
entry_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
content_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),
|
||||
description = table.Column<string>(type: "text", nullable: true),
|
||||
word_count = table.Column<int>(type: "integer", nullable: true),
|
||||
sort_order = table.Column<int>(type: "integer", nullable: false),
|
||||
is_active = table.Column<bool>(type: "boolean", nullable: false),
|
||||
source_hash = table.Column<string>(type: "character varying(128)", maxLength: 128, 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_vocabulary_units", x => x.id);
|
||||
table.UniqueConstraint("ak_vocabulary_units_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.ForeignKey(
|
||||
name: "fk_vocabulary_units_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_vocabulary_units_content_nodes_tenant_id_content_node_id",
|
||||
columns: x => new { x.tenant_id, x.content_node_id },
|
||||
principalTable: "content_nodes",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_vocabulary_units_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_vocabulary_units_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "handbook_chapters",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
subject_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
entry_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
content_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),
|
||||
description = 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),
|
||||
source_hash = table.Column<string>(type: "character varying(128)", maxLength: 128, 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_handbook_chapters", x => x.id);
|
||||
table.UniqueConstraint("ak_handbook_chapters_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.ForeignKey(
|
||||
name: "fk_handbook_chapters_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_handbook_chapters_content_nodes_tenant_id_content_node_id",
|
||||
columns: x => new { x.tenant_id, x.content_node_id },
|
||||
principalTable: "content_nodes",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_handbook_chapters_handbook_subjects_tenant_id_subject_id",
|
||||
columns: x => new { x.tenant_id, x.subject_id },
|
||||
principalTable: "handbook_subjects",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_handbook_chapters_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "vocabulary_words",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
unit_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
entry_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
content_node_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
||||
word = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
|
||||
phonetic = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
|
||||
meaning = table.Column<string>(type: "text", nullable: true),
|
||||
example = table.Column<string>(type: "text", nullable: true),
|
||||
example_translation = table.Column<string>(type: "text", nullable: true),
|
||||
difficulty = table.Column<int>(type: "integer", nullable: true),
|
||||
tags = 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),
|
||||
source_hash = table.Column<string>(type: "character varying(128)", maxLength: 128, 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_vocabulary_words", x => x.id);
|
||||
table.UniqueConstraint("ak_vocabulary_words_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.ForeignKey(
|
||||
name: "fk_vocabulary_words_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_vocabulary_words_content_nodes_tenant_id_content_node_id",
|
||||
columns: x => new { x.tenant_id, x.content_node_id },
|
||||
principalTable: "content_nodes",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_vocabulary_words_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_vocabulary_words_vocabulary_units_tenant_id_unit_id",
|
||||
columns: x => new { x.tenant_id, x.unit_id },
|
||||
principalTable: "vocabulary_units",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "handbook_entries",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
chapter_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
entry_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
content_node_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
|
||||
title = table.Column<string>(type: "character varying(500)", maxLength: 500, nullable: false),
|
||||
summary = table.Column<string>(type: "text", nullable: true),
|
||||
content = table.Column<string>(type: "text", nullable: true),
|
||||
tags = 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),
|
||||
source_hash = table.Column<string>(type: "character varying(128)", maxLength: 128, 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_handbook_entries", x => x.id);
|
||||
table.UniqueConstraint("ak_handbook_entries_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.ForeignKey(
|
||||
name: "fk_handbook_entries_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_handbook_entries_content_nodes_tenant_id_content_node_id",
|
||||
columns: x => new { x.tenant_id, x.content_node_id },
|
||||
principalTable: "content_nodes",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_handbook_entries_handbook_chapters_tenant_id_chapter_id",
|
||||
columns: x => new { x.tenant_id, x.chapter_id },
|
||||
principalTable: "handbook_chapters",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_handbook_entries_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "user_word_favorites",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
word_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
legacy_id = table.Column<string>(type: "text", nullable: true),
|
||||
legacy_user_id = table.Column<string>(type: "text", nullable: true),
|
||||
legacy_word_id = table.Column<string>(type: "text", nullable: true),
|
||||
note = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
|
||||
favorited_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", 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_user_word_favorites", x => x.id);
|
||||
table.UniqueConstraint("ak_user_word_favorites_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.ForeignKey(
|
||||
name: "fk_user_word_favorites_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_user_word_favorites_users_user_id",
|
||||
column: x => x.user_id,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_user_word_favorites_vocabulary_words_tenant_id_word_id",
|
||||
columns: x => new { x.tenant_id, x.word_id },
|
||||
principalTable: "vocabulary_words",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "user_word_progress",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
user_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
word_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
legacy_id = table.Column<string>(type: "text", nullable: true),
|
||||
legacy_user_id = table.Column<string>(type: "text", nullable: true),
|
||||
legacy_word_id = table.Column<string>(type: "text", nullable: true),
|
||||
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
correct_count = table.Column<int>(type: "integer", nullable: false),
|
||||
wrong_count = table.Column<int>(type: "integer", nullable: false),
|
||||
last_review_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
next_review_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
review_count = table.Column<int>(type: "integer", nullable: false),
|
||||
correct_streak = table.Column<int>(type: "integer", nullable: false),
|
||||
ease_factor = table.Column<decimal>(type: "numeric(4,2)", precision: 4, scale: 2, nullable: false, defaultValue: 2.50m),
|
||||
last_result = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
||||
due_level = 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_user_word_progress", x => x.id);
|
||||
table.UniqueConstraint("ak_user_word_progress_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.CheckConstraint("ck_user_word_progress_correct_streak", "correct_streak >= 0");
|
||||
table.CheckConstraint("ck_user_word_progress_ease_factor", "ease_factor >= 1.30 and ease_factor <= 3.00");
|
||||
table.CheckConstraint("ck_user_word_progress_review_count", "review_count >= 0");
|
||||
table.ForeignKey(
|
||||
name: "fk_user_word_progress_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_user_word_progress_users_user_id",
|
||||
column: x => x.user_id,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_user_word_progress_vocabulary_words_tenant_id_word_id",
|
||||
columns: x => new { x.tenant_id, x.word_id },
|
||||
principalTable: "vocabulary_words",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_chapters_tenant_id_content_node_id",
|
||||
table: "handbook_chapters",
|
||||
columns: new[] { "tenant_id", "content_node_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_chapters_tenant_id_entry_id_content_node_id_subjec~",
|
||||
table: "handbook_chapters",
|
||||
columns: new[] { "tenant_id", "entry_id", "content_node_id", "subject_id", "is_active", "sort_order" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_chapters_tenant_id_legacy_id",
|
||||
table: "handbook_chapters",
|
||||
columns: new[] { "tenant_id", "legacy_id" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_chapters_tenant_id_subject_id",
|
||||
table: "handbook_chapters",
|
||||
columns: new[] { "tenant_id", "subject_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_entries_tenant_id_chapter_id",
|
||||
table: "handbook_entries",
|
||||
columns: new[] { "tenant_id", "chapter_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_entries_tenant_id_content_node_id",
|
||||
table: "handbook_entries",
|
||||
columns: new[] { "tenant_id", "content_node_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_entries_tenant_id_entry_id_content_node_id_chapter~",
|
||||
table: "handbook_entries",
|
||||
columns: new[] { "tenant_id", "entry_id", "content_node_id", "chapter_id", "is_active", "sort_order" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_entries_tenant_id_legacy_id",
|
||||
table: "handbook_entries",
|
||||
columns: new[] { "tenant_id", "legacy_id" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_subjects_tenant_id_content_node_id",
|
||||
table: "handbook_subjects",
|
||||
columns: new[] { "tenant_id", "content_node_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_subjects_tenant_id_entry_id_content_node_id_region~",
|
||||
table: "handbook_subjects",
|
||||
columns: new[] { "tenant_id", "entry_id", "content_node_id", "region_id", "is_active", "sort_order" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_subjects_tenant_id_legacy_id",
|
||||
table: "handbook_subjects",
|
||||
columns: new[] { "tenant_id", "legacy_id" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_subjects_tenant_id_major_id",
|
||||
table: "handbook_subjects",
|
||||
columns: new[] { "tenant_id", "major_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_subjects_tenant_id_region_id",
|
||||
table: "handbook_subjects",
|
||||
columns: new[] { "tenant_id", "region_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_handbook_subjects_tenant_id_school_id",
|
||||
table: "handbook_subjects",
|
||||
columns: new[] { "tenant_id", "school_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_question_type_groups_tenant_id_legacy_id",
|
||||
table: "question_type_groups",
|
||||
columns: new[] { "tenant_id", "legacy_id" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_question_type_groups_tenant_id_subject_id_is_active_sort_or~",
|
||||
table: "question_type_groups",
|
||||
columns: new[] { "tenant_id", "subject_id", "is_active", "sort_order" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_subject_shares_tenant_id_target_subject_id",
|
||||
table: "subject_shares",
|
||||
columns: new[] { "tenant_id", "target_subject_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_user_word_favorites_tenant_id_user_id_word_id",
|
||||
table: "user_word_favorites",
|
||||
columns: new[] { "tenant_id", "user_id", "word_id" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_user_word_favorites_tenant_id_word_id",
|
||||
table: "user_word_favorites",
|
||||
columns: new[] { "tenant_id", "word_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_user_word_favorites_user_id",
|
||||
table: "user_word_favorites",
|
||||
column: "user_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_user_word_progress_tenant_id_user_id_next_review_at_status_~",
|
||||
table: "user_word_progress",
|
||||
columns: new[] { "tenant_id", "user_id", "next_review_at", "status", "due_level" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_user_word_progress_tenant_id_user_id_word_id",
|
||||
table: "user_word_progress",
|
||||
columns: new[] { "tenant_id", "user_id", "word_id" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_user_word_progress_tenant_id_word_id",
|
||||
table: "user_word_progress",
|
||||
columns: new[] { "tenant_id", "word_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_user_word_progress_user_id",
|
||||
table: "user_word_progress",
|
||||
column: "user_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_vocabulary_units_tenant_id_content_node_id",
|
||||
table: "vocabulary_units",
|
||||
columns: new[] { "tenant_id", "content_node_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_vocabulary_units_tenant_id_entry_id_content_node_id_region_~",
|
||||
table: "vocabulary_units",
|
||||
columns: new[] { "tenant_id", "entry_id", "content_node_id", "region_id", "is_active", "sort_order" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_vocabulary_units_tenant_id_legacy_id",
|
||||
table: "vocabulary_units",
|
||||
columns: new[] { "tenant_id", "legacy_id" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_vocabulary_units_tenant_id_region_id",
|
||||
table: "vocabulary_units",
|
||||
columns: new[] { "tenant_id", "region_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_vocabulary_words_tenant_id_content_node_id",
|
||||
table: "vocabulary_words",
|
||||
columns: new[] { "tenant_id", "content_node_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_vocabulary_words_tenant_id_entry_id_content_node_id_unit_id~",
|
||||
table: "vocabulary_words",
|
||||
columns: new[] { "tenant_id", "entry_id", "content_node_id", "unit_id", "is_active", "sort_order" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_vocabulary_words_tenant_id_legacy_id",
|
||||
table: "vocabulary_words",
|
||||
columns: new[] { "tenant_id", "legacy_id" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_vocabulary_words_tenant_id_unit_id_is_active_sort_order_cre~",
|
||||
table: "vocabulary_words",
|
||||
columns: new[] { "tenant_id", "unit_id", "is_active", "sort_order", "created_at" });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "handbook_entries");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "question_type_groups");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "subject_shares");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "user_word_favorites");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "user_word_progress");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "handbook_chapters");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "vocabulary_words");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "handbook_subjects");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "vocabulary_units");
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user