Repository navigation
feat(tenants): replace inline InMemoryTenantRepository with Postgres repository and migration - #1660
Open
devogechukwu wants to merge 1 commit into
Open
devogechukwu wants to merge 1 commit into
devogechukwu wants to merge 1 commit into
Conversation
…sitory and migration
|
@devogechukwu Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the inline
InMemoryTenantRepositoryinsrc/routes/tenants.tswith a dedicated repository module (src/repositories/tenantRepository.ts), a PostgreSQL-backedPostgresTenantRepository, and a database migration so tenants persist across restarts and are shared across instances while keeping the HTTP contract unchanged.Changes
TenantRecord,TenantRepository,slugifyTenantName, andInMemoryTenantRepositoryout ofsrc/routes/tenants.ts, and addedPostgresTenantRepository.list(actorId)returns only tenants created byactorId.create(input, actorId)maps duplicate slug violations (SQLSTATE23505in Postgres / slug collision in memory) toConflictError(HTTP 409, codeCONFLICT).update(tenantId, input, actorId)scopes updates toWHERE id = $id AND created_by = $actorIdand throwsNotFoundError('Tenant not found')(HTTP 404, codeNOT_FOUND) for both unknown and cross-actor IDs.tenantstable (id TEXT PRIMARY KEY,name,slug UNIQUE,contact_email,plan CHECK (plan IN ('starter', 'growth', 'enterprise')),metadata JSONB,created_by,created_at,updated_at, andidx_tenants_created_byindex) plus rollback migration.TenantRecordandTenantRepository, adds optionalpooltoTenantsRouterDeps, and defaults toPostgresTenantRepositorywhen a pool orDATABASE_URL(outside demo mode) is available, keepingdeps.tenantRepositoryinjection and all HTTP envelopes/ETag/validation unchanged.InMemoryTenantRepositoryandPostgresTenantRepository(viapg-mem), including metadata JSON round-trip, missing optional fields, slug uniqueness (409 CONFLICT), partial update merging, cross-actor vs unknown404, and restart persistence.Testing
node_moduleswas not installed in this environment; CI will executetenantRepository.test.ts, quarantined tenant route tests,npm run db:check-migrations, andnpm run typecheck.Closes #1560