mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-05 02:09:29 +01:00
Reported as separate complaints; nearly all of them were one cause.
Nineteen plpgsql functions write to a column, table or type that does not
exist. plpgsql only plans a statement when it RUNS, so each raised 42703
the moment a user triggered it and at no other time. Every one looked
healthy: defined, listed by \df, routed by PostgREST, called happily by
the app. Nine of them are the timeline.
like/unlike_timeline_event, dislike/undislike_timeline_event
end with `UPDATE timeline_events SET like_count = ...` under a
comment reading "if column exists". timeline_events has no count
columns and never has; the counts live in timeline_event_stats,
which the line above already updates correctly. Since a function
body is one transaction, the raise rolled back the INSERT three
lines earlier — so the like was written, then unwritten. The UI
applied its optimistic update, saw success:false and rolled back,
which is why the heart filled for ~150ms and emptied again.
add_timeline_comment, delete_timeline_comment
same line, same column, so replies never saved either.
soft_delete_timeline_event
checked `SELECT user_id FROM profiles WHERE role = 'admin'`.
profiles has neither column. And even fixed it would not have
worked: it set only deleted_at while every read path filters
is_deleted. Production confirms nothing ever took this path — 102
events have both flags, zero have deleted_at alone. Both are set
now, the reason goes in the deletion_reason COLUMN that exists,
and the phantom admin branch is gone rather than repaired: it
could never have run, so nothing real is lost, and a moderator
capability should be built deliberately against a table that
exists.
create_quote_reply
failed three separate ways, each hidden behind the last: assigned
text into a jsonb column, incremented a quote_count that does not
exist, named four columns notifications does not have, used a
`type` its CHECK constraint forbids, and never set the NOT NULL
subject_type — so it could not have succeeded on any input. It
also never wrote `description`, which is the field PostContent
renders, so a quote reply would have shown as an empty post.
Verified by clicking Like on orangecat.ch/timeline and reading the
response: HTTP 400, 42703. Each function was then rehearsed against
production inside a transaction and rolled back — like returns 1 and
lands in timeline_event_stats, delete returns true and the row is
genuinely hidden, a quote reply creates with a non-empty body and
notifies its author.
THE GATE, because nineteen is not a run of bad luck. plpgsql_check reads
every function body against the live schema and reports exactly this
class. Exposed as count_broken_plpgsql_functions() over PostgREST, in
the same shape as count_email_derived_usernames, and ratcheted in
check-data-invariants.mjs at the eleven that remain. Its limits are
stated where it is defined: it is static, so a NOT NULL left unset or a
CHECK violation still only fails at runtime — both of which
create_quote_reply also did.
Nothing else could have caught these. Unit tests mock the database;
check-rpc-exists proves a function is DEFINED, which all nineteen were;
migration replay proves the SQL applies, and creating a function never
validates its body.
Ctrl+Enter was a different bug with the same shape — it worked, and
looked like it did not. The post was created; the composer kept the
text, because the effect syncing content into the contentEditable bails
whenever the editor is the active element, which it always is right
after a keystroke. So the obvious response was to press again, and the
server rejected that as a duplicate. Clicking the button never showed it
because a click moves focus to the button first. A reset to empty is now
exempt from that guard: there is nothing to clobber.
UI, following X rather than inventing:
The action row was five near-identical JSX blocks that had already
drifted — one had -ml-2, some had titles, the reply count was computed
by an inline three-way IIFE. It is one config-driven component now.
Counts render into a fixed-width tabular slot instead of collapsing to
'' at zero, so liking something no longer reflows the row and slides
every later icon under the cursor that just clicked it.
Edit post: Save moves from the header to the bottom right, beside the
character count that decides whether it is allowed, instead of
diagonally opposite it.
Repost: the quoted post now sits directly under what you are writing,
with the buttons last. The action row used to separate the composer
from the thing it refers to. The textarea loses its border — the
dialog is already the container.
Claude-Session: https://claude.ai/code/session_012dpTLxh5GJWeWTF1UEvcD5
Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Scripts Directory
This directory contains all automation scripts organized by purpose.
Directory Structure
analysis/- Bundle analysis, documentation checking, and optimization toolsauth-fix/- Scripts to fix authentication and RLS policy issuesdb/- Database operations, migrations, and schema management- Migration scripts moved from root:
apply-migration.js,apply-*-migration.js - Old schema files archived in
db/archive/
- Migration scripts moved from root:
deployment/- Deployment, production setup, and monitoring scriptsdev/- Development helpers, local setup, and debugging toolsdiagnostics/- Health checks and system diagnosticsmaintenance/- Cleanup, optimization, and maintenance scriptsmonitoring/- Performance monitoring and bundle size trackingoauth/- OAuth provider setup and configurationprofile-fix/- Scripts to fix profile-related issuesschema-fix/- Database schema fixes and migrationsstorage/- Supabase storage bucket setup and managementtest/- Testing utilities and validation scripts- Test/debug scripts moved from root:
test-*.js,check-*.js,debug-*.js
- Test/debug scripts moved from root:
Usage
Most scripts can be run with:
node scripts/{category}/script-name.js
For deployment scripts:
bash scripts/deployment/script-name.sh
Important Scripts
scripts/dev/dev-start.js- Main development server starterscripts/deployment/browser-verify.js- Post-deploy browser smoke test (deploys themselves happen on the box — see docs/deployment/DEPLOYMENT_PROCESS.md)scripts/db/apply-migrations.ts- Database migrationsscripts/maintenance/cleanup-console-logs.ts- Remove console.log statements