سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 08:00 UTC
docs: record phase 1A readonly parity drift and sync bypass approval gate
davoodmehraban89 committed
Oct 16, 2026 at 12:51 UTC
9a107a27cf0216b65cdddd101928e15b30b134ac
1 file changed
+23
docs/FINORA_PHASE1A_READONLY_PREFLIGHT_2026-10-16.md
new
+23
@@ -0,0 +1,23 @@
1
+# Finora Phase 1A — Read-only preflight and approval stop
2
+Date: 2026-10-16. Repository: `davoodmehraban89/Factor-easy`; inspected protected main SHA `bccd474433b4188e43aae345773498ea6fc65209`. Production ref: `hcsixhqbyuhpshfwqpjx`. All production queries were read-only catalog or aggregate SELECT. NO Production DDL/DML and NO phase-1 migration written.
3
+
4
+## Condition 3: mandatory schema/source parity
5
+- Repo migration files: **81**; Production recorded migrations: **82**.
6
+- Strict filename/version set comparison: **25 Production migration IDs absent from repo**, **24 repo filenames absent from Production migration history**. Most are timestamp-renumbered request/workflow/identity migrations, which alone do not prove divergent resulting DDL. Full manifest must be mapped by *content* before change.
7
+- **Confirmed material drift:** Production migration `20261007165208_phone_identity_profile` has no tracked counterpart, and live `public.profiles.phone` exists. Latest repo `20261012080000_fix_identity_bootstrap_license_before_membership.sql` references `profiles.phone` and `auth.users.phone`, so replaying the repo cannot be assumed to reproduce the live identity schema.
8
+- Further unmatched repo-only versions include `20260929222000_iran_enterprise_foundation_collections.sql`, `20260930222500_iran_enterprise_control_collections.sql`, and `20260930223000_iran_enterprise_financial_controls.sql`; their resulting DDL has NOT yet been compared against every live object.
9
+- CI baseline `.github/workflows/quality.yml` runs **three synthetic PostgreSQL 17 services** using partial fixture/setup SQL, not a full Supabase CLI stack. Therefore no legitimate claim of whole-schema equality or RLS/security-definer behavior from existing CI; full object-by-object comparison of tables, functions, triggers, policies, grants and signatures against a Supabase CLI schema clone is **NOT VERIFIED**.
10
+- Live subset inspected: `records` has organization-scoped PK `(organization_id,collection,id)`; two `finora_sync_records` signatures (jsonb,jsonb) and (jsonb,jsonb,uuid); `records.version` and `finora_post_event` absent (these are planned capabilities, not baseline drift); `records` RLS enabled and 4 policies; posted journal triggers run **BEFORE UPDATE/DELETE only**. Relevant catalog definitions reviewed read-only.
11
+
12
+**Gate: MATERIAL SCHEMA DRIFT PRESENT. STOP before writing migrations. First reconcile production-only phone schema and migration identity mapping and create a complete isolated Supabase CLI reconstruction + reproducible schema diff, without modifying Production.**
13
+
14
+## Condition 4: bypass via sync / JSONB journal fields
15
+- Client `js/sync.js` diff/push passes entire `data` JSONB objects to `sb.rpc('finora_sync_records', {p_upserts, p_deletes})`, with **no version token, no server-only field filter**; `pullAll()` fetches `collection,id,data` only. `js/journal-engine.js` sets `journalVouchers.status`, `number`, `postedAt`, `postedBy` on the browser.
16
+- Both live `finora_sync_records` functions upsert full JSONB `data`, with **no rejection of status/number/postedAt fields**, and `SECURITY INVOKER` RLS does not implement field-level restrictions. Authorized write-capable users can attempt to post a `draft` journal or create one with `status='posted'` directly. Parent posted guard examines `OLD.status`, so draft->posted is not rejected on balance, and INSERT is not intercepted. Parent journal children guard similarly protects UPDATE/DELETE only. This is an architecture-level bypass, not a production mutation test.
17
+- Live `records` PK is organization-scoped, but legacy two-argument sync `ON CONFLICT(owner_id,collection,id)` no longer matches any matching unique key in the inspected `records` indexes. Three-argument sync uses the current org PK. The browser sends only two named arguments, while the 3-arg overload has a default for organization; live dispatch/compatibility **requires isolated end-to-end verification**, not a promise of success.
18
+- Live `anon` table grants may include INSERT, but RLS only allows `authenticated` policies: grants alone do NOT establish anonymous insert.
19
+- Status/number security must be enforced in server context for all write routes including direct PostgREST table insert/update, both existing sync signatures, and future authorized RPC, while supporting explicit planned transition/legacy usage. Test write attempts with real local `anon`/`authenticated`/`service_role`, tenant A/B, RLS, and trigger context before release.
20
+- Production journal inventory was read-only checked separately: 9 posted/reversed documents, 18 journal lines, no detected orphan lines; none of 9 inspected posted/reversed documents were unbalanced or had fewer than two lines. This is a limited snapshot, NOT runtime security proof.
21
+
22
+## Next action requiring owner approval
23
+Accept this preflight as **BLOCKED / NOT COMPLETE** and explicitly authorize **read-only migration-history reconciliation and isolated Supabase CLI schema reconstruction/diff** before implementation of 1A. No Production DDL/DML, no credentials copied to GitHub, no Phase 1B, no migration files until these discrepancies are closed. Then resubmit the complete parity report and await owner's next gate.