chore: add Drizzle schema and generated migrations for default and per-server databases#7395
Conversation
…r-server databases
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (1)
🧰 Additional context used📓 Path-based instructions (3)**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{js,jsx,ts,tsx,json}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🔇 Additional comments (5)
WalkthroughIntroduces Drizzle ORM as the database layer for two separate SQLite databases (app and servers). Adds TypeScript schema definitions for 16 tables total, generates initial SQL migrations and Drizzle Kit snapshots for both databases, wires Expo migration entry points, exports row type aliases via a central schema index, and validates query shapes with a Jest test suite. ChangesDrizzle ORM Database Infrastructure
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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 |
diegolmello
left a comment
There was a problem hiding this comment.
Structural review (NATIVE-1275). Schema is column-complete vs the WatermelonDB source and the generated migrations are clean drizzle-kit output (no hand-edits). Two findings worth acting on before merge are inline below.
Minor notes, not blocking: the two near-identical drizzle.app.config.ts / drizzle.servers.config.ts exist only because drizzle-kit takes one schema target per config — a one-line comment saying so would stop a future "dedupe" that breaks generation. The mixed indentation in migrations/*/migrations.js is drizzle-kit's own Expo-template output (both files are prettier-ignored), so it's not actionable.
diegolmello
left a comment
There was a problem hiding this comment.
Review: Drizzle schema + generated migrations
Schema-only foundation; nothing imports it yet. Quality is high — I diffed all 16 tables (13 per-server + 3 servers-db) column-by-column against the WatermelonDB schemas in app/lib/database/schema/ and found full parity: no missing tables, no missing columns, correct SQLite affinities (incl. real() for the WMDB number/boolean cases), and every WMDB index reproduced. The deliberate choices (universal nullability, keeping verbatim SQLite column names) are clearly motivated.
Findings are all minor / process-level, no inline anchors needed:
🟡 [medium] No db:generate npm script for either config — the test instructions tell reviewers to run pnpm exec drizzle-kit generate --config drizzle.app.config.ts (and the servers variant) by hand. A "db:generate:app" / "db:generate:servers" pair makes the regenerate→diff loop repeatable for the next PR author.
🟡 [medium] The servers schema (serversTable, usersServersTable, serversHistoryTable) has zero query-shape test coverage — queryShapes.test.ts imports only from ./app. Add at least one serversTable and one usersServersTable lookup so a future divergence is caught.
🟢 [low] Generated files (*.sql, _journal.json, migrations.js, 0000_snapshot.json) have no trailing newline and are in .eslintignore/.prettierignore, so the hook won't fix them — expect noisy diffs on every regeneration unless normalised.
🟢 [low] All *_at/ts/ls timestamp columns are real() (correct WMDB parity — they store integer epoch-ms in a REAL-affinity column). Worth a one-line schema comment so accessor authors don't expect a Date.
Open question for the wipe-and-restore migration (not this PR): WMDB non-optional string columns default to '' on insert, never NULL, but the Drizzle schema makes them all nullable; and users_count was a WMDB string historically, now read as a number. When legacy rows are copied, watch for '' → NULL and '' → NaN/0 drift where downstream code does === '' checks.
Reviewed by an automated pass; treat comments as suggestions, not blockers.
…unused Insert types - Extract shared messageColumns object spread into messagesTable, threadsTable, and threadMessagesTable; table-specific fields (tmid/tmsg/blocks/tshow/md/comment for messages; tmid/draft_message for threads; subscription_id for thread_messages) added per-table. messages.alias and messages.parse_urls override the shared nullable default to notNull. - Add .notNull() to all columns whose WMDB counterpart lacks isOptional, across subscriptions, rooms, messages, threads, thread_messages, custom_emojis, frequently_used_emojis, uploads, permissions, users (app), and servers_history. - Remove 16 TXxxInsert aliases (InferInsertModel-based) from index.ts; none are consumed in this or any stacked branch. - Regenerate Drizzle migrations (drizzle-kit generate) for both app and servers schemas; new SQL files and snapshots committed. Claude-Session: https://claude.ai/code/session_01TE9VsFTeXsXc8ssqeR8MJ7
…into 0000 Replace the two-migration sequence (0000 nullable + 0001 ALTER) with a single 0000 baseline that already carries all NOT NULL columns. Nothing has shipped, so there are no existing databases to migrate from the old 0000. App: 0000_wise_mockingbird.sql Servers: 0000_puzzling_colleen_wing.sql Claude-Session: https://claude.ai/code/session_01TE9VsFTeXsXc8ssqeR8MJ7
|
Android Build Available Rocket.Chat 4.74.0.109170 Internal App Sharing: https://play.google.com/apps/test/RQQ8k09hlnQ/ahAO29uNQbp5ToHhpjSoUnR9ZhV5aIR9rLs8w3VACcC8g7MoJ_cDNuAKv8FthmOlXD-7ig8SNz-h34hDeOHse0zI5T |
|
iOS Build Available Rocket.Chat 4.74.0.109171 |
Proposed changes
First code step of the WatermelonDB → expo-sqlite + Drizzle migration: adds the Drizzle ORM schema definitions and generated SQL migrations for both databases, plus the drizzle-kit tooling configs. No runtime behavior changes — nothing imports these modules yet.
app/lib/database/driver/schema/):app.ts— the 13 per-server tables (messages,subscriptions,rooms,threads,thread_messages,custom_emojis,frequently_used_emojis,uploads,settings,roles,permissions,slash_commands,users) with exact WatermelonDB table/column name parity.servers.ts— the 3 default-database tables (servers,users,servers_history).index.ts— typed exports and table registries for both database kinds.app/lib/database/driver/migrations/): drizzle-kit output (SQL + snapshots + journal +migrations.jsfor the expo driver), one folder per database.drizzle.app.config.ts/drizzle.servers.config.ts(dialectsqlite, driverexpo).drizzle-orm0.45.2 (runtime),drizzle-kit0.31.10 (dev).Schema decisions (from the migration PRD):
_status,_changed) are dropped — the new layer does not use WatermelonDB's sync protocol.idtext primary keys, matching WatermelonDB's actual SQLite DDL (it emits noNOT NULLconstraints on data columns), so the wipe-and-restore migration can re-insert any legacy row without constraint failures.Issue(s)
https://rocketchat.atlassian.net/browse/NATIVE-1275
How to test or reproduce
TZ=UTC pnpm test app/lib/database/driver— schema tests assert table/column parity against the WatermelonDB schema and pin the generated SQL shapes of representative queries.pnpm exec tsc --noEmit -p .— type-checks the schema exports.pnpm exec drizzle-kit generate --config drizzle.app.config.ts(and the servers config) produces no diff.Screenshots
N/A — no UI changes.
Types of changes
Checklist
Further comments
Part of the WatermelonDB replacement track. The driver adapter (connection lifecycle, SQLCipher keying, live-query hooks) follows in a separate PR built on top of this one.
Summary by CodeRabbit