From db6cda427afdade01668ed228d4cd718fa883da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Fri, 29 May 2026 19:05:33 +0300 Subject: [PATCH] ci(rebuild): support pd_processing_log + tenant_operations_log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Нужно для cleanup третьей таблицы (pd_processing_log_y2026_m05) после race condition. tenant_operations_log добавлен для полноты покрытия 4 из 6 audit-таблиц (auth_log + saas_admin_audit_log — BYPASSRLS global, не per-tenant). Co-Authored-By: Claude Opus 4.7 (1M context) --- .github/workflows/sql-rebuild-audit-chain.yml | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) 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 <