feat: migration 0015 — channel protection settings (protect_lgbtqia, protect_women) - #78
Conversation
🤖 CodeAnt AI — Review Status
|
✅ Deploy Preview for moderaty ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Sequence DiagramThis PR adds two per-channel protection flags to the database schema. Existing and new channels default to disabled, while explicit protection settings can be stored without changing the existing tenancy constraint. sequenceDiagram
participant Migration Runner
participant Database
participant Application
Migration Runner->>Database: Apply channel settings migration
Database->>Database: Add two protection flags with default disabled
Database-->>Migration Runner: Existing channels read as disabled
Application->>Database: Create channel without protection settings
Database-->>Application: Store both flags as disabled
Application->>Database: Create channel with protection enabled
Database-->>Application: Store explicit protection settings
Generated by CodeAnt AI |
There was a problem hiding this comment.
This migration adds per-channel protection settings (protect_lgbtqia and protect_women) with proper backward compatibility. The implementation is solid with expand-only schema changes, appropriate defaults (0 for off-by-default), and comprehensive test coverage.
All critical aspects are correctly implemented:
- SQL migration uses NOT NULL DEFAULT 0 to fill existing rows without backfill
- Schema definitions match the migration structure
- Test fixtures updated to include new columns
- Migration tests verify column existence, constraints, defaults, and tenancy contract preservation
The changes follow established patterns and maintain database integrity. Ready for merge once dev DB verification is confirmed (as noted in the PR description).
You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | ✅ 7 (≤ 100 complexity) |
| Duplication | ✅ -1 (≤ 1 duplication) |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
🏁 CodeAnt Quality Gate ResultsCommit: ✅ Overall Status: PASSEDQuality Gate Details
|
PR Summary by QodoMigration 0015: add per-channel protect_lgbtqia/protect_women flags
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
1. Unguarded reads via channels schema
|
| toneLevel: integer('tone_level'), // moderation sensitivity: null or 1 = omni only, 2 = omni + tone pass | ||
| protectLgbtqia: integer('protect_lgbtqia').notNull().default(0), // protection setting: 1 = heightened protection for comments targeting LGBTQIA+ people | ||
| protectWomen: integer('protect_women').notNull().default(0), // protection setting: 1 = heightened protection for comments targeting women | ||
| createdAt: text('created_at').notNull().default(sql`(strftime('%Y-%m-%dT%H:%M:%fZ', 'now'))`) |
There was a problem hiding this comment.
2. Unguarded reads via channels schema 📘 Rule violation ≡ Correctness
New channels columns were added to the Drizzle schema, but some runtime code selects all channels columns (no projection), which can fail with no such column if the migration hasn't been applied yet. This violates the requirement to guard reads of newly added columns or guarantee migrations run before serving traffic.
Agent Prompt
## Issue description
Adding new columns to the Drizzle `channels` schema can break existing `select().from(channels)` queries (which select all schema columns) when the database has not yet received the migration.
## Issue Context
There is no visible runtime guarantee that migrations are applied before handlers/jobs execute, so reads must be guarded or queries must avoid implicitly selecting newly-added columns.
## Fix Focus Areas
- src/lib/server/db/schema.ts[101-106]
- src/lib/server/pipeline.ts[515-533]
- src/lib/server/db/index.ts[30-48]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| { | ||
| "idx": 15, | ||
| "version": "6", | ||
| "when": 1785879950529, | ||
| "tag": "0015_channels_protect_flags", | ||
| "breakpoints": true |
There was a problem hiding this comment.
3. Spaces indentation in drizzle json 📘 Rule violation ⚙ Maintainability
The changed Drizzle meta JSON files use leading spaces for indentation instead of tabs. This violates the repository indentation rule for changed source files.
Agent Prompt
## Issue description
Changed Drizzle meta JSON uses space-indentation, violating the tabs-only indentation rule.
## Issue Context
These files are part of the committed source-of-truth for migrations, and the rule requires tabs for indentation in changed files.
## Fix Focus Areas
- drizzle/meta/_journal.json[106-116]
- drizzle/meta/0015_snapshot.json[1-25]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
…lpers Codacy flagged 2 new clones in migration-0015.test.ts (migratedDb + afterEach client tracking, tenancy-contract insert) copied from the 0014 test. Extract applyMigration/closeMigratedDbs/expectTenancyContract into migrationTestUtils and use them in all three migration tests, so the scaffolding exists once. Assertions unchanged; 0013's migratedDb also gains the client-close tracking it lacked.
|
Warning Review limit reached
Next review available in: 11 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Review triage (round 1)qodo-code-review — "Unguarded reads via channels schema" (schema.ts:106): valid as a systemic observation, not actionable in this migration PR. The full-row qodo-code-review — "Spaces indentation in drizzle json" (_journal.json:115): invalid, not fixing. Codacy — "2 new code clones" in amazon-q-developer: approving review, no findings — thanks. Snyk failures ( |
Dev verification — COMPLETE (was pending the Turso 502 outage)The earlier hollow exit-0 was confirmed: dev had 15 migrations after the first migrate (the 0007 pattern — drizzle-kit exited 0 during the upstream outage without applying). Re-ran dev (
prod (
Ready for human merge. |




User description
What
Per-channel protection settings, database lane only (the settings UI and scoring behavior belong to the backend/frontend agents). Expand-only per I7:
drizzle/0015_channels_protect_flags.sql:channelsgainsprotect_lgbtqiaandprotect_women, bothinteger NOT NULL DEFAULT 0— themarketing_opt_inconvention for off-by-default toggles. The DEFAULT fills existing rows in place; no backfill statement needed.schema.ts: both columns aftertoneLevel(settings grouping), with semantics comments.src/lib/server/db/migration-0015.test.ts: behavior tests in the 0013/0014 pattern (failing first, then green).src/lib/server/testdb.ts: fixture gains both columns.Behavior tests
channels_org_requires_ownerstill bitesVerification
npx vitest run src/lib/server/db/migration-0015.test.ts: 3/3 (watched ENOENT red → green)npm run check0/0,npm run test51 files / 430 tests green,npm run buildclean, codacy-analysis 0 issues on all changed filesnpm run db:migrateexited 0, but the dev Turso upstream went 502 (connect to upstream failed, also viaturso db shell dev) immediately afterwards, so the post-application verification (0007-incident rule: verify the schema, not the exit code) has not run yet. I will verify (16 migrations, both columns present, existing rows read 0) and confirm in a comment as soon as the dev DB recovers. If the earlier run proves hollow,npm run db:migratewill simply be re-run.Prod application: human per DEPLOY.md §1 after merge, then
scripts/verify-tenancy.mjsmust end ALL CHECKS PASSED.CodeAnt-AI Description
Add per-channel protection settings for LGBTQIA+ people and women
What Changed
Impact
✅ Per-channel protection controls✅ Safe defaults for existing channels✅ Preserved channel ownership rules💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.