{
  "metadata": {
    "generated_at": "2026-06-03T07:02:39.791349+00:00",
    "stage": "HRMS_REAL_USER_MASTER_DATA_MINIMAL_SCHEMA_PREP_PACK_Y"
  },
  "db_read_status": "DB_READ_AVAILABLE",
  "existing_table_reuse_analysis": {
    "db_read_status": "DB_READ_AVAILABLE",
    "exact_reusable_tables": [],
    "selected_existing_table": {},
    "fuzzy_match_candidates": [
      "public.employee_profile_previews",
      "public.position_capability_previews"
    ],
    "reuse_decision": "reuse_existing_tables_where_exact_match_exists_otherwise_create_candidate",
    "reason": "No duplicate creation is proposed for exact existing tables; fuzzy matches require later manual mapping before reuse."
  },
  "target_schema_design": {
    "departments": {
      "columns": [
        "department_id TEXT PRIMARY KEY",
        "tenant_id TEXT",
        "company_key TEXT",
        "department_code TEXT",
        "department_name TEXT NOT NULL",
        "parent_department_id TEXT",
        "department_type TEXT",
        "status TEXT NOT NULL",
        "source TEXT",
        "feishu_department_id TEXT",
        "data_version TEXT",
        "source_asset_ref TEXT",
        "audit_id TEXT",
        "rollback_ref TEXT",
        "metadata JSONB DEFAULT '{}'",
        "created_by TEXT",
        "created_at TIMESTAMPTZ DEFAULT now()",
        "updated_by TEXT",
        "updated_at TIMESTAMPTZ DEFAULT now()",
        "cancelled_at TIMESTAMPTZ",
        "cancelled_by TEXT",
        "cancel_reason TEXT"
      ],
      "create_if_missing": true,
      "reuse_if_existing": false
    },
    "positions": {
      "columns": [
        "position_id TEXT PRIMARY KEY",
        "tenant_id TEXT",
        "company_key TEXT",
        "position_code TEXT",
        "position_name TEXT NOT NULL",
        "department_id TEXT",
        "job_level TEXT",
        "job_family TEXT",
        "role_type TEXT",
        "status TEXT NOT NULL",
        "capability_model_ref TEXT",
        "data_version TEXT",
        "source_asset_ref TEXT",
        "audit_id TEXT",
        "rollback_ref TEXT",
        "metadata JSONB DEFAULT '{}'",
        "created_by TEXT",
        "created_at TIMESTAMPTZ DEFAULT now()",
        "updated_by TEXT",
        "updated_at TIMESTAMPTZ DEFAULT now()",
        "cancelled_at TIMESTAMPTZ",
        "cancelled_by TEXT",
        "cancel_reason TEXT"
      ],
      "create_if_missing": true,
      "reuse_if_existing": false
    },
    "employees": {
      "columns": [
        "employee_id TEXT PRIMARY KEY",
        "tenant_id TEXT",
        "company_key TEXT",
        "employee_code TEXT",
        "employee_name_masked TEXT NOT NULL",
        "real_name_encrypted_or_ref TEXT",
        "department_id TEXT",
        "position_id TEXT",
        "manager_employee_id TEXT",
        "employment_status TEXT NOT NULL",
        "employee_type TEXT",
        "trial_scope TEXT",
        "is_real_trial_candidate BOOLEAN DEFAULT false",
        "source TEXT",
        "data_version TEXT",
        "source_asset_ref TEXT",
        "audit_id TEXT",
        "rollback_ref TEXT",
        "metadata JSONB DEFAULT '{}'",
        "created_by TEXT",
        "created_at TIMESTAMPTZ DEFAULT now()",
        "updated_by TEXT",
        "updated_at TIMESTAMPTZ DEFAULT now()",
        "cancelled_at TIMESTAMPTZ",
        "cancelled_by TEXT",
        "cancel_reason TEXT"
      ],
      "create_if_missing": true,
      "reuse_if_existing": false
    },
    "permission_subjects": {
      "columns": [
        "permission_subject_id TEXT PRIMARY KEY",
        "tenant_id TEXT",
        "company_key TEXT",
        "subject_type TEXT NOT NULL",
        "employee_id TEXT",
        "role_key TEXT",
        "display_name_masked TEXT",
        "status TEXT NOT NULL",
        "permission_scope JSONB DEFAULT '{}'",
        "data_version TEXT",
        "source_asset_ref TEXT",
        "audit_id TEXT",
        "rollback_ref TEXT",
        "metadata JSONB DEFAULT '{}'",
        "created_by TEXT",
        "created_at TIMESTAMPTZ DEFAULT now()",
        "updated_by TEXT",
        "updated_at TIMESTAMPTZ DEFAULT now()",
        "cancelled_at TIMESTAMPTZ",
        "cancelled_by TEXT",
        "cancel_reason TEXT"
      ],
      "create_if_missing": true,
      "reuse_if_existing": false
    },
    "employee_role_assignments": {
      "columns": [
        "role_assignment_id TEXT PRIMARY KEY",
        "tenant_id TEXT",
        "company_key TEXT",
        "employee_id TEXT",
        "permission_subject_id TEXT",
        "role_key TEXT NOT NULL",
        "scope_type TEXT",
        "scope_ref TEXT",
        "status TEXT NOT NULL",
        "data_version TEXT",
        "source_asset_ref TEXT",
        "audit_id TEXT",
        "rollback_ref TEXT",
        "metadata JSONB DEFAULT '{}'",
        "created_by TEXT",
        "created_at TIMESTAMPTZ DEFAULT now()",
        "updated_by TEXT",
        "updated_at TIMESTAMPTZ DEFAULT now()"
      ],
      "create_if_missing": true,
      "reuse_if_existing": false
    },
    "feishu_user_mappings": {
      "columns": [
        "feishu_user_mapping_id TEXT PRIMARY KEY",
        "tenant_id TEXT",
        "company_key TEXT",
        "employee_id TEXT",
        "permission_subject_id TEXT",
        "feishu_user_id TEXT",
        "feishu_open_id TEXT",
        "feishu_union_id TEXT",
        "feishu_department_id TEXT",
        "mapping_status TEXT NOT NULL",
        "writeback_allowed BOOLEAN DEFAULT false",
        "dry_run_only BOOLEAN DEFAULT true",
        "sensitive_payload_ref TEXT",
        "data_version TEXT",
        "source_asset_ref TEXT",
        "audit_id TEXT",
        "rollback_ref TEXT",
        "metadata JSONB DEFAULT '{}'",
        "created_by TEXT",
        "created_at TIMESTAMPTZ DEFAULT now()",
        "updated_by TEXT",
        "updated_at TIMESTAMPTZ DEFAULT now()"
      ],
      "create_if_missing": true,
      "reuse_if_existing": false
    }
  },
  "candidate_sql_path": "/root/.openclaw/workspace/talent-review-system/docs/roadmap/hrms_real_user_master_data_minimal_schema_candidate.sql",
  "rollback_candidate_sql_path": "/root/.openclaw/workspace/talent-review-system/docs/roadmap/hrms_real_user_master_data_minimal_schema_rollback_candidate.sql",
  "field_mapping": {
    "employee_csv_to_employees_mapping": {
      "employee_code": "employee_code",
      "display_name": "employee_name_masked",
      "department_code": "department_id via departments.department_code",
      "position_code": "position_id via positions.position_code",
      "manager_employee_code": "manager_employee_id via employees.employee_code",
      "employment_status": "employment_status",
      "job_level": "metadata.job_level",
      "trial_scope": "trial_scope",
      "real_trial_prefix": "metadata.real_trial_prefix"
    },
    "department_csv_to_departments_mapping": {
      "department_code": "department_code",
      "department_name": "department_name",
      "parent_department_code": "parent_department_id via departments.department_code",
      "department_type": "department_type",
      "business_unit": "metadata.business_unit",
      "real_trial_prefix": "metadata.real_trial_prefix"
    },
    "position_csv_to_positions_mapping": {
      "position_code": "position_code",
      "position_name": "position_name",
      "department_code": "department_id via departments.department_code",
      "job_family": "job_family",
      "job_level": "job_level",
      "critical_position_flag": "metadata.critical_position_flag",
      "real_trial_prefix": "metadata.real_trial_prefix"
    },
    "permission_subject_mapping": {
      "employee_id": "permission_subjects.employee_id",
      "role_key": "permission_subjects.role_key",
      "display_name_masked": "permission_subjects.display_name_masked",
      "permission_scope": "permission_subjects.permission_scope"
    },
    "role_assignment_mapping": {
      "employee_id": "employee_role_assignments.employee_id",
      "permission_subject_id": "employee_role_assignments.permission_subject_id",
      "role_key": "employee_role_assignments.role_key",
      "scope_type": "employee_role_assignments.scope_type",
      "scope_ref": "employee_role_assignments.scope_ref"
    },
    "feishu_mapping": {
      "employee_code": "employee_id via employees.employee_code",
      "feishu_user_key_masked": "sensitive_payload_ref or feishu_user_id/open_id after future token gate",
      "feishu_department_key_masked": "feishu_department_id",
      "writeback_allowed": "writeback_allowed=false",
      "dry_run_only": "dry_run_only=true"
    },
    "required_fields": [
      "tenant_id",
      "company_key",
      "status",
      "data_version",
      "source_asset_ref",
      "audit_id",
      "rollback_ref"
    ],
    "optional_fields": [
      "metadata",
      "cancelled_at",
      "cancelled_by",
      "cancel_reason"
    ],
    "fields_not_supported_yet": [
      "formal HR employee PII",
      "payroll fields",
      "performance fields",
      "recruiting fields"
    ],
    "future_migration_fields": [
      "strong foreign keys after baseline stabilizes",
      "encrypted PII vault reference",
      "Feishu token-backed external id verification"
    ],
    "sensitive_fields_handling": [
      "只保存脱敏姓名或加密引用",
      "不在 JSON/页面输出手机号、邮箱、身份证号",
      "Feishu 标识当前只保留 masked/ref，不反写"
    ]
  },
  "migration_required": true,
  "write_ready": false,
  "next_gate": "REAL_USER_MASTER_DATA_SCHEMA_APPLY_GATE_READY",
  "next_task": "HRMS_REAL_USER_MASTER_DATA_MINIMAL_SCHEMA_APPLY_PACK_Y1",
  "approval_statement_template": "批准执行 HRMS_REAL_USER_MASTER_DATA_MINIMAL_SCHEMA_APPLY_PACK_Y1：仅应用真实试跑主数据最小 schema migration，不导入真实员工、不创建真实测评任务、不反写飞书。",
  "candidate_tables": [
    "departments",
    "positions",
    "employees",
    "permission_subjects",
    "employee_role_assignments",
    "feishu_user_mappings"
  ],
  "skipped_existing_tables": [],
  "redline_checks": {
    "writes_database": false,
    "schema_migration_executed": false,
    "real_employee_imported": false,
    "real_department_imported": false,
    "real_position_imported": false,
    "permission_subject_created": false,
    "feishu_mapping_created": false,
    "real_assignment_created": false,
    "people_action_executed": false,
    "feishu_writeback_executed": false,
    "backend_modified": false,
    "permission_rule_modified": false
  },
  "page_update_status": {
    "import_prep_schema_status_card_visible": true
  },
  "modified_files_after_validation": [
    "/var/www/talent-review/hrms-real-user-master-data-import-prep.html"
  ]
}