feat: multi-tenant community resolver with RLS isolation (#82)
* refactor(config): rename COMMUNITY_MODE 'global' to 'multi'
Aligns with multi-tenant design: 'single' for self-hosters, 'multi'
for Barazo SaaS with hostname-based community resolution.
* refactor(schema): make communityDid the primary key for community_settings
Remove singleton id column, add domains JSONB column for custom domain
configuration. communityDid is now the primary key, enabling per-community
settings in multi-tenant mode.
* feat(middleware): add CommunityResolver with hostname-based resolution
Introduces CommunityResolver interface with single-mode implementation.
Fastify onRequest hook resolves community from hostname, sets
request.communityDid, and configures RLS session variable.
* refactor(routes): replace getCommunityDid(env) with request.communityDid
Community DID is now resolved per-request by the CommunityResolver
middleware instead of read from process-level env config. Removes
getCommunityDid import from all 9 route files.
* refactor(queries): replace WHERE id='default' with communityDid lookups
All community_settings queries now use communityDid as the lookup key.
Adds requireCommunityDid() helper for type-safe extraction from request.
Updates setup service to accept communityDid parameter. Removes id column
references from serializers and JSON schemas.
* feat(schema): add RLS tenant isolation policies to all community-scoped tables
Enables Row-Level Security on 17 tables across 15 schema files using
pgPolicy with current_setting('app.current_community_did'). Creates
barazo_app database role for policy enforcement. Tables without
communityDid (users, firehose, trust graph) are excluded.
* test: update all tests for multi-tenant schema changes
Fix 400 test failures across 13 test files by adding communityDid
request decoration, replacing 'global' with 'multi', updating
setup service call signatures, and adjusting mock query chains.
* test(rls): add tenant isolation integration tests
- Add tenant-isolation.test.ts using testcontainers with host networking
to verify PostgreSQL RLS policies across two communities
- Tests cover SELECT/INSERT/UPDATE/DELETE isolation, aggregator mode,
and withCheck enforcement blocking cross-tenant writes
- Fix lint errors: require-await, unnecessary type assertions, template
literal types, unsafe assignment
- Fix Fastify onRequest hooks in 15 test files to use done() callback
pattern instead of async (prevents request hanging)
- Add roles.ts to drizzle.config.ts schema list
authored by