Files
tiku-backend.net/Tiku.Infrastructure/Persistence/Migrations/20260725212328_AddLearningReportsAndPracticeAccessPersistence.cs

765 lines
43 KiB
C#

using System;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Tiku.Infrastructure.Persistence.Migrations
{
/// <inheritdoc />
public partial class AddLearningReportsAndPracticeAccessPersistence : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<JsonElement>(
name: "access_rules",
table: "question_collections",
type: "jsonb",
nullable: false,
defaultValueSql: "'{}'::jsonb");
migrationBuilder.AddColumn<Guid>(
name: "access_entitlement_id",
table: "practice_sessions",
type: "uuid",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "access_mode",
table: "practice_sessions",
type: "character varying(32)",
maxLength: 32,
nullable: false,
defaultValue: "free");
migrationBuilder.AddColumn<JsonElement>(
name: "access_snapshot",
table: "practice_sessions",
type: "jsonb",
nullable: false,
defaultValueSql: "'{}'::jsonb");
migrationBuilder.AddColumn<int>(
name: "consumed_free_quota",
table: "practice_sessions",
type: "integer",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<JsonElement>(
name: "access_rules",
table: "practice_blueprints",
type: "jsonb",
nullable: false,
defaultValueSql: "'{}'::jsonb");
migrationBuilder.AddColumn<JsonElement>(
name: "access_rules",
table: "content_nodes",
type: "jsonb",
nullable: false,
defaultValueSql: "'{}'::jsonb");
migrationBuilder.CreateTable(
name: "dashboard_daily_stats",
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),
legacy_region_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
stat_date = table.Column<DateOnly>(type: "date", nullable: false),
new_users = table.Column<int>(type: "integer", nullable: false),
new_questions = table.Column<int>(type: "integer", nullable: false),
new_orders = table.Column<int>(type: "integer", nullable: false),
new_revenue_cents = table.Column<int>(type: "integer", nullable: false),
active_users = table.Column<int>(type: "integer", nullable: false),
rebuilt_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_dashboard_daily_stats", x => x.id);
table.UniqueConstraint("ak_dashboard_daily_stats_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_dashboard_daily_stats_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_dashboard_daily_stats_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "exam_dates",
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),
exam_name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: false),
exam_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
exam_type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
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),
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_exam_dates", x => x.id);
table.UniqueConstraint("ak_exam_dates_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_exam_dates_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_exam_dates_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_exam_dates_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "practice_access_events",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
user_id = table.Column<Guid>(type: "uuid", nullable: true),
practice_session_id = table.Column<Guid>(type: "uuid", nullable: true),
event_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
access_mode = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
requested_count = table.Column<int>(type: "integer", nullable: false),
granted_count = table.Column<int>(type: "integer", nullable: false),
consumed_free_quota = table.Column<int>(type: "integer", nullable: false),
reason = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
scope_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
scope_id = table.Column<Guid>(type: "uuid", nullable: true),
entitlement_id = table.Column<Guid>(type: "uuid", 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()")
},
constraints: table =>
{
table.PrimaryKey("pk_practice_access_events", x => x.id);
table.UniqueConstraint("ak_practice_access_events_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_practice_access_events_consumed_free_quota", "consumed_free_quota >= 0");
table.CheckConstraint("ck_practice_access_events_granted_count", "granted_count >= 0");
table.CheckConstraint("ck_practice_access_events_requested_count", "requested_count >= 0");
table.ForeignKey(
name: "fk_practice_access_events_practice_sessions_tenant_id_practice~",
columns: x => new { x.tenant_id, x.practice_session_id },
principalTable: "practice_sessions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "fk_practice_access_events_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_practice_access_events_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "practice_daily_usage",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column<Guid>(type: "uuid", nullable: false),
usage_date = table.Column<DateOnly>(type: "date", nullable: false, defaultValueSql: "current_date"),
scope_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
scope_id = table.Column<Guid>(type: "uuid", nullable: true),
free_limit = table.Column<int>(type: "integer", nullable: false),
used_count = table.Column<int>(type: "integer", 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_practice_daily_usage", x => x.id);
table.UniqueConstraint("ak_practice_daily_usage_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_practice_daily_usage_free_limit", "free_limit >= 0");
table.CheckConstraint("ck_practice_daily_usage_used_count", "used_count >= 0");
table.ForeignKey(
name: "fk_practice_daily_usage_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_practice_daily_usage_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "practice_session_reports",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
user_id = table.Column<Guid>(type: "uuid", nullable: false),
practice_session_id = table.Column<Guid>(type: "uuid", nullable: false),
blueprint_id = table.Column<Guid>(type: "uuid", nullable: true),
collection_id = table.Column<Guid>(type: "uuid", nullable: true),
mode = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
total_questions = table.Column<int>(type: "integer", nullable: false),
answered_count = table.Column<int>(type: "integer", nullable: false),
correct_count = table.Column<int>(type: "integer", nullable: false),
wrong_count = table.Column<int>(type: "integer", nullable: false),
unanswered_count = table.Column<int>(type: "integer", nullable: false),
score = table.Column<decimal>(type: "numeric(10,2)", precision: 10, scale: 2, nullable: false),
total_score = table.Column<decimal>(type: "numeric(10,2)", precision: 10, scale: 2, nullable: false),
accuracy = table.Column<decimal>(type: "numeric(6,4)", precision: 6, scale: 4, nullable: false),
duration_seconds = table.Column<int>(type: "integer", nullable: false),
started_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
submitted_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
section_stats = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
question_results = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
wrong_question_ids = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
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_practice_session_reports", x => x.id);
table.UniqueConstraint("ak_practice_session_reports_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_practice_session_reports_accuracy", "accuracy >= 0 and accuracy <= 1");
table.CheckConstraint("ck_practice_session_reports_counts", "total_questions >= 0 and answered_count >= 0 and correct_count >= 0 and wrong_count >= 0 and unanswered_count >= 0");
table.CheckConstraint("ck_practice_session_reports_duration", "duration_seconds >= 0");
table.CheckConstraint("ck_practice_session_reports_scores", "score >= 0 and total_score >= 0");
table.ForeignKey(
name: "fk_practice_session_reports_practice_blueprints_tenant_id_blue~",
columns: x => new { x.tenant_id, x.blueprint_id },
principalTable: "practice_blueprints",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_practice_session_reports_practice_sessions_tenant_id_practi~",
columns: x => new { x.tenant_id, x.practice_session_id },
principalTable: "practice_sessions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_practice_session_reports_question_collections_tenant_id_col~",
columns: x => new { x.tenant_id, x.collection_id },
principalTable: "question_collections",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_practice_session_reports_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_practice_session_reports_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "reports",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
question_id = table.Column<Guid>(type: "uuid", nullable: true),
user_id = table.Column<Guid>(type: "uuid", nullable: true),
handled_by = table.Column<Guid>(type: "uuid", nullable: true),
legacy_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
title = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
category = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
description = table.Column<string>(type: "text", nullable: true),
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
priority = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
handled_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
resolution = table.Column<string>(type: "text", nullable: true),
contact = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
attachments = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"),
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_reports", x => x.id);
table.UniqueConstraint("ak_reports_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_reports_questions_tenant_id_question_id",
columns: x => new { x.tenant_id, x.question_id },
principalTable: "questions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Restrict);
table.ForeignKey(
name: "fk_reports_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_reports_users_handled_by",
column: x => x.handled_by,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
table.ForeignKey(
name: "fk_reports_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.CreateTable(
name: "revenue_daily_stats",
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),
legacy_region_id = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true),
stat_date = table.Column<DateOnly>(type: "date", nullable: false),
sale_type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
real_revenue_cents = table.Column<int>(type: "integer", nullable: false),
order_count = table.Column<int>(type: "integer", nullable: false),
code_count = table.Column<int>(type: "integer", nullable: false),
code_used = table.Column<int>(type: "integer", nullable: false),
code_estimated = table.Column<int>(type: "integer", nullable: false),
estimated_revenue_cents = table.Column<int>(type: "integer", nullable: false),
rebuilt_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_revenue_daily_stats", x => x.id);
table.UniqueConstraint("ak_revenue_daily_stats_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_revenue_daily_stats_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_revenue_daily_stats_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "user_score_events",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
user_id = table.Column<Guid>(type: "uuid", nullable: false),
event_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
points = table.Column<int>(type: "integer", nullable: false),
balance_after = table.Column<int>(type: "integer", nullable: false),
source_type = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
source_id = table.Column<Guid>(type: "uuid", nullable: true),
idempotency_key = table.Column<string>(type: "character varying(200)", maxLength: 200, 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()")
},
constraints: table =>
{
table.PrimaryKey("pk_user_score_events", x => x.id);
table.UniqueConstraint("ak_user_score_events_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_user_score_events_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_user_score_events_users_user_id",
column: x => x.user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "practice_session_report_sections",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
report_id = table.Column<Guid>(type: "uuid", nullable: false),
practice_session_id = table.Column<Guid>(type: "uuid", nullable: false),
section_key = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
section_name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
question_type = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
question_count = table.Column<int>(type: "integer", nullable: false),
answered_count = table.Column<int>(type: "integer", nullable: false),
correct_count = table.Column<int>(type: "integer", nullable: false),
wrong_count = table.Column<int>(type: "integer", nullable: false),
unanswered_count = table.Column<int>(type: "integer", nullable: false),
score = table.Column<decimal>(type: "numeric(10,2)", precision: 10, scale: 2, nullable: false),
total_score = table.Column<decimal>(type: "numeric(10,2)", precision: 10, scale: 2, nullable: false),
accuracy = table.Column<decimal>(type: "numeric(6,4)", precision: 6, scale: 4, nullable: false),
sort_order = table.Column<int>(type: "integer", 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_practice_session_report_sections", x => x.id);
table.UniqueConstraint("ak_practice_session_report_sections_tenant_id_id", x => new { x.tenant_id, x.id });
table.CheckConstraint("ck_practice_session_report_sections_accuracy", "accuracy >= 0 and accuracy <= 1");
table.CheckConstraint("ck_practice_session_report_sections_counts", "question_count >= 0 and answered_count >= 0 and correct_count >= 0 and wrong_count >= 0 and unanswered_count >= 0");
table.CheckConstraint("ck_practice_session_report_sections_scores", "score >= 0 and total_score >= 0");
table.ForeignKey(
name: "fk_practice_session_report_sections_practice_session_reports_t~",
columns: x => new { x.tenant_id, x.report_id },
principalTable: "practice_session_reports",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_practice_session_report_sections_practice_sessions_tenant_i~",
columns: x => new { x.tenant_id, x.practice_session_id },
principalTable: "practice_sessions",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_practice_session_report_sections_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "report_status_events",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
report_id = table.Column<Guid>(type: "uuid", nullable: false),
from_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
to_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
note = table.Column<string>(type: "text", nullable: true),
actor_user_id = table.Column<Guid>(type: "uuid", 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()")
},
constraints: table =>
{
table.PrimaryKey("pk_report_status_events", x => x.id);
table.UniqueConstraint("ak_report_status_events_tenant_id_id", x => new { x.tenant_id, x.id });
table.ForeignKey(
name: "fk_report_status_events_reports_tenant_id_report_id",
columns: x => new { x.tenant_id, x.report_id },
principalTable: "reports",
principalColumns: new[] { "tenant_id", "id" },
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_report_status_events_tenants_tenant_id",
column: x => x.tenant_id,
principalTable: "tenants",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_report_status_events_users_actor_user_id",
column: x => x.actor_user_id,
principalTable: "users",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
});
migrationBuilder.AddCheckConstraint(
name: "ck_practice_sessions_consumed_free_quota",
table: "practice_sessions",
sql: "consumed_free_quota >= 0");
migrationBuilder.CreateIndex(
name: "ix_dashboard_daily_stats_tenant_id_legacy_id",
table: "dashboard_daily_stats",
columns: new[] { "tenant_id", "legacy_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_dashboard_daily_stats_tenant_id_region_id",
table: "dashboard_daily_stats",
columns: new[] { "tenant_id", "region_id" });
migrationBuilder.CreateIndex(
name: "ix_dashboard_daily_stats_tenant_id_stat_date_region_id",
table: "dashboard_daily_stats",
columns: new[] { "tenant_id", "stat_date", "region_id" },
unique: true)
.Annotation("Npgsql:NullsDistinct", false);
migrationBuilder.CreateIndex(
name: "ix_exam_dates_tenant_id_legacy_id",
table: "exam_dates",
columns: new[] { "tenant_id", "legacy_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_exam_dates_tenant_id_region_id",
table: "exam_dates",
columns: new[] { "tenant_id", "region_id" });
migrationBuilder.CreateIndex(
name: "ix_exam_dates_tenant_id_school_id_exam_at",
table: "exam_dates",
columns: new[] { "tenant_id", "school_id", "exam_at" });
migrationBuilder.CreateIndex(
name: "ix_practice_access_events_tenant_id_practice_session_id",
table: "practice_access_events",
columns: new[] { "tenant_id", "practice_session_id" });
migrationBuilder.CreateIndex(
name: "ix_practice_access_events_tenant_id_user_id_created_at",
table: "practice_access_events",
columns: new[] { "tenant_id", "user_id", "created_at" });
migrationBuilder.CreateIndex(
name: "ix_practice_access_events_user_id",
table: "practice_access_events",
column: "user_id");
migrationBuilder.CreateIndex(
name: "ix_practice_daily_usage_tenant_id_user_id_usage_date",
table: "practice_daily_usage",
columns: new[] { "tenant_id", "user_id", "usage_date" });
migrationBuilder.CreateIndex(
name: "ix_practice_daily_usage_tenant_id_user_id_usage_date_scope_typ~",
table: "practice_daily_usage",
columns: new[] { "tenant_id", "user_id", "usage_date", "scope_type", "scope_id" },
unique: true)
.Annotation("Npgsql:NullsDistinct", false);
migrationBuilder.CreateIndex(
name: "ix_practice_daily_usage_user_id",
table: "practice_daily_usage",
column: "user_id");
migrationBuilder.CreateIndex(
name: "ix_practice_session_report_sections_tenant_id_practice_session~",
table: "practice_session_report_sections",
columns: new[] { "tenant_id", "practice_session_id" });
migrationBuilder.CreateIndex(
name: "ix_practice_session_report_sections_tenant_id_report_id_sectio~",
table: "practice_session_report_sections",
columns: new[] { "tenant_id", "report_id", "section_key" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_practice_session_report_sections_tenant_id_report_id_sort_o~",
table: "practice_session_report_sections",
columns: new[] { "tenant_id", "report_id", "sort_order" });
migrationBuilder.CreateIndex(
name: "ix_practice_session_reports_tenant_id_blueprint_id_submitted_at",
table: "practice_session_reports",
columns: new[] { "tenant_id", "blueprint_id", "submitted_at" },
filter: "blueprint_id is not null");
migrationBuilder.CreateIndex(
name: "ix_practice_session_reports_tenant_id_collection_id",
table: "practice_session_reports",
columns: new[] { "tenant_id", "collection_id" });
migrationBuilder.CreateIndex(
name: "ix_practice_session_reports_tenant_id_practice_session_id",
table: "practice_session_reports",
columns: new[] { "tenant_id", "practice_session_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_practice_session_reports_tenant_id_user_id_submitted_at",
table: "practice_session_reports",
columns: new[] { "tenant_id", "user_id", "submitted_at" });
migrationBuilder.CreateIndex(
name: "ix_practice_session_reports_user_id",
table: "practice_session_reports",
column: "user_id");
migrationBuilder.CreateIndex(
name: "ix_report_status_events_actor_user_id",
table: "report_status_events",
column: "actor_user_id");
migrationBuilder.CreateIndex(
name: "ix_report_status_events_tenant_id_report_id_created_at",
table: "report_status_events",
columns: new[] { "tenant_id", "report_id", "created_at" });
migrationBuilder.CreateIndex(
name: "ix_reports_handled_by",
table: "reports",
column: "handled_by");
migrationBuilder.CreateIndex(
name: "ix_reports_tenant_id_legacy_id",
table: "reports",
columns: new[] { "tenant_id", "legacy_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_reports_tenant_id_question_id_created_at",
table: "reports",
columns: new[] { "tenant_id", "question_id", "created_at" },
filter: "question_id is not null");
migrationBuilder.CreateIndex(
name: "ix_reports_tenant_id_status_created_at",
table: "reports",
columns: new[] { "tenant_id", "status", "created_at" });
migrationBuilder.CreateIndex(
name: "ix_reports_user_id",
table: "reports",
column: "user_id");
migrationBuilder.CreateIndex(
name: "ix_revenue_daily_stats_tenant_id_legacy_id",
table: "revenue_daily_stats",
columns: new[] { "tenant_id", "legacy_id" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_revenue_daily_stats_tenant_id_region_id",
table: "revenue_daily_stats",
columns: new[] { "tenant_id", "region_id" });
migrationBuilder.CreateIndex(
name: "ix_revenue_daily_stats_tenant_id_stat_date_region_id_sale_type",
table: "revenue_daily_stats",
columns: new[] { "tenant_id", "stat_date", "region_id", "sale_type" },
unique: true)
.Annotation("Npgsql:NullsDistinct", false);
migrationBuilder.CreateIndex(
name: "ix_user_score_events_tenant_id_idempotency_key",
table: "user_score_events",
columns: new[] { "tenant_id", "idempotency_key" },
unique: true);
migrationBuilder.CreateIndex(
name: "ix_user_score_events_tenant_id_user_id_created_at",
table: "user_score_events",
columns: new[] { "tenant_id", "user_id", "created_at" });
migrationBuilder.CreateIndex(
name: "ix_user_score_events_user_id",
table: "user_score_events",
column: "user_id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "dashboard_daily_stats");
migrationBuilder.DropTable(
name: "exam_dates");
migrationBuilder.DropTable(
name: "practice_access_events");
migrationBuilder.DropTable(
name: "practice_daily_usage");
migrationBuilder.DropTable(
name: "practice_session_report_sections");
migrationBuilder.DropTable(
name: "report_status_events");
migrationBuilder.DropTable(
name: "revenue_daily_stats");
migrationBuilder.DropTable(
name: "user_score_events");
migrationBuilder.DropTable(
name: "practice_session_reports");
migrationBuilder.DropTable(
name: "reports");
migrationBuilder.DropCheckConstraint(
name: "ck_practice_sessions_consumed_free_quota",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "access_rules",
table: "question_collections");
migrationBuilder.DropColumn(
name: "access_entitlement_id",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "access_mode",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "access_snapshot",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "consumed_free_quota",
table: "practice_sessions");
migrationBuilder.DropColumn(
name: "access_rules",
table: "practice_blueprints");
migrationBuilder.DropColumn(
name: "access_rules",
table: "content_nodes");
}
}
}