diff --git a/.github/workflows/sql-rebuild-audit-chain.yml b/.github/workflows/sql-rebuild-audit-chain.yml index d10d5e59..4c7bc00a 100644 --- a/.github/workflows/sql-rebuild-audit-chain.yml +++ b/.github/workflows/sql-rebuild-audit-chain.yml @@ -23,12 +23,14 @@ on: required: true type: string table_kind: - description: 'activity_log или balance_transactions' + description: 'activity_log | balance_transactions | pd_processing_log | tenant_operations_log' required: true type: choice options: - activity_log - balance_transactions + - pd_processing_log + - tenant_operations_log confirm_apply: description: 'Подтверждаю выполнение mutating cleanup' required: true @@ -68,6 +70,18 @@ jobs: exit 1 fi ;; + pd_processing_log) + if [[ ! "$PARTITION" =~ ^pd_processing_log_y[0-9]{4}_m[0-9]{2}$ ]]; then + echo "::error::partition '$PARTITION' не соответствует table_kind=pd_processing_log" + exit 1 + fi + ;; + tenant_operations_log) + if [[ ! "$PARTITION" =~ ^tenant_operations_log_y[0-9]{4}_m[0-9]{2}$ ]]; then + echo "::error::partition '$PARTITION' не соответствует table_kind=tenant_operations_log" + exit 1 + fi + ;; *) echo "::error::table_kind unknown" exit 1 @@ -87,12 +101,21 @@ jobs: - name: Execute SQL rebuild on prod run: | - # Build ROW expression per table_kind - if [[ "$TABLE_KIND" = "activity_log" ]]; then - ROW_EXPR="ROW(t.id, t.tenant_id, t.user_id, t.deal_id, t.event, t.old_value, t.new_value, t.context, t.ip_address, t.user_agent, NULL::bytea, t.created_at)" - else - ROW_EXPR="ROW(t.id, t.tenant_id, t.type, t.amount_rub, t.amount_leads, t.balance_rub_after, t.balance_leads_after, t.description, t.related_type, t.related_id, t.user_id, t.admin_user_id, NULL::bytea, t.created_at)" - fi + # Build ROW expression per table_kind (mirror AuditChainConfig::TABLES) + case "$TABLE_KIND" in + activity_log) + ROW_EXPR="ROW(t.id, t.tenant_id, t.user_id, t.deal_id, t.event, t.old_value, t.new_value, t.context, t.ip_address, t.user_agent, NULL::bytea, t.created_at)" + ;; + balance_transactions) + ROW_EXPR="ROW(t.id, t.tenant_id, t.type, t.amount_rub, t.amount_leads, t.balance_rub_after, t.balance_leads_after, t.description, t.related_type, t.related_id, t.user_id, t.admin_user_id, NULL::bytea, t.created_at)" + ;; + pd_processing_log) + ROW_EXPR="ROW(t.id, t.tenant_id, t.subject_type, t.subject_id, t.action, t.purpose, t.actor_tenant_user_id, t.actor_admin_user_id, t.ip_address, NULL::bytea, t.created_at)" + ;; + tenant_operations_log) + ROW_EXPR="ROW(t.id, t.tenant_id, t.user_id, t.entity_type, t.entity_id, t.event, t.payload_before, t.payload_after, t.ip_address, t.user_agent, NULL::bytea, t.created_at)" + ;; + esac # Build SQL with substituted PARTITION + FROM_ID + ROW_EXPR cat > /tmp/rebuild.sql <