PostgreSQL schema and local verification
Use PostgreSQL 16 or newer. Historical JSONB values are checked with pg_input_is_valid before typed comparisons; this is a runtime requirement as well as a migration requirement.
db/structure.sql is the schema source of truth. Ruby schema dumps do not preserve our database triggers. Financial records, audit events, issued documents, delivery snapshots and webhook attempts have database protections in addition to application checks.
Use PostgreSQL client tools matching the server version for ordinary rails db:migrate and rails db:schema:load. Current local verification uses PostgreSQL 17. Migration 012 also restores protections on databases previously rebuilt from the old Ruby dump.
Where PostgreSQL runs in a local Docker container and client tools are not installed on the host, use the included helper with the normal database environment variables:
BILLING_POSTGRES_CONTAINER=your-postgres ruby script/postgres-local.rb dump RAILS_ENV=test BILLING_POSTGRES_CONTAINER=your-postgres ruby script/postgres-local.rb prepare-test
dump accepts only billing_rails_development. prepare-test accepts only billing_rails_test; it rebuilds that synthetic test schema when the checked-in SQL hash changes. It loads the schema transactionally, including migration versions and triggers, then records Rails’ schema fingerprint. It does not modify the development database. Do not run schema rebuilds concurrently with test workers.
The SQL file contains schema and migration versions, never customer records. Private Billwerk imports remain under the ignored private/imports/ directory.