Skip to content

Embed migrations from the single root directory - #266

Merged
martsokha merged 1 commit into
mainfrom
chore/single-migrations-dir
Sep 4, 2026
Merged

Embed migrations from the single root directory#266
martsokha merged 1 commit into
mainfrom
chore/single-migrations-dir

Conversation

@martsokha

@martsokha martsokha commented Sep 4, 2026

Copy link
Copy Markdown
Member

Problem

embed_migrations!() embedded a copy of the migrations under crates/nvisy-postgres/src/migrations, kept in sync from the canonical root migrations/ by a copy step in make generate-migrations. That duplication was a silent split-brain risk: editing a root migration without regenerating left the compiled binary embedding a stale copy — no error, just drift between the DB and the binary.

Change

Point embed_migrations! at the root directory directly — embed_migrations!("../../migrations"), resolved from the crate's manifest dir — so there is one source of truth. The diesel CLI already ran against ./migrations (per diesel.toml); the copy only ever fed the macro.

  • build.rs now reruns on ../../migrations (not the deleted copy), preserving the rebuild-on-change behavior the proc-macro's limitation requires.
  • Makefile: dropped the copy / mkdir / rm steps and the MIGRATIONS_IN_DIR / MIGRATIONS_OUT_DIR vars; generate-migrations now just runs migrations + regenerates schema.rs, and clear-migrations just reverts.
  • Removed the redundant embedded copy directory (it was gitignored / untracked).
  • Freshened the stale diesel.toml comment.

Verification

make generate-migrations regenerates an identical schema.rs (no diff), confirming the root migrations produce the same schema. The copy directory does not reappear. Full gate green: cargo check (workspace), clippy (-D warnings), fmt --check.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores

    • Simplified migration generation and cleanup workflows.
    • Standardized the repository’s root migrations directory as the single source for database migrations.
    • Updated migration change detection so rebuilds respond to changes in the shared migrations directory.
  • Documentation

    • Clarified migration-directory configuration and usage.

`embed_migrations!()` embedded a copy of the migrations under
`crates/nvisy-postgres/src/migrations`, kept in sync from the root `migrations/`
by a `make generate-migrations` copy step. That duplication was a silent
split-brain risk: editing a root migration without regenerating left the compiled
binary embedding a stale copy.

Point `embed_migrations!` at the root directory directly
(`embed_migrations!("../../migrations")`, resolved from the crate manifest) so
there is one source of truth. The diesel CLI already ran against `./migrations`
(per `diesel.toml`), so the copy only ever fed the macro.

- `build.rs` reruns on `../../migrations` (not the deleted copy), preserving the
  rebuild-on-migration-change behavior the proc-macro limitation needs.
- Drop the copy/mkdir/rm steps and the `MIGRATIONS_IN_DIR`/`MIGRATIONS_OUT_DIR`
  vars from `generate-migrations` and `clear-migrations`; they only run and revert
  now.
- Remove the redundant embedded copy directory (it was gitignored / untracked).

Verified: `make generate-migrations` regenerates an identical `schema.rs`, and the
copy directory no longer reappears.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018bKk1YEG4tZ69jzYVQvQL8
@martsokha martsokha added chore maintenance, dependency updates, code cleanup postgres ORM, models, queries, migrations labels Sep 4, 2026
@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Essentials

Run ID: 3c8aa261-11fa-49f2-8cd6-1cd9b410cf50

📥 Commits

Reviewing files that changed from the base of the PR and between b55a4b3 and b2244b2.

📒 Files selected for processing (4)
  • Makefile
  • crates/nvisy-postgres/build.rs
  • crates/nvisy-postgres/src/lib.rs
  • diesel.toml

Included review availability: 0 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


📝 Walkthrough

Walkthrough

The migration workflow now uses the repository-root migrations/ directory as its single source. The Makefile no longer copies migrations. The build script watches the root directory, and embed_migrations! embeds it directly.

Changes

Migration source consolidation

Layer / File(s) Summary
Canonical migration embedding
crates/nvisy-postgres/build.rs, crates/nvisy-postgres/src/lib.rs, diesel.toml
nvisy-postgres embeds migrations from ../../migrations. Cargo watches the same directory. diesel.toml documents it as the canonical source.
Migration command workflow
Makefile
generate-migrations regenerates the schema without copying migrations. clear-migrations only reverts database migrations.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to b2244

Migration embedding and generation now use the repository-root migrations directory as the single source of truth, removing the copy workflow without identified current-head merge risk.

Sequence Diagram(s)

sequenceDiagram
  participant Developer
  participant Makefile
  participant Diesel
  participant RootMigrations
  participant nvisy-postgres
  Developer->>Makefile: Run migration command
  Makefile->>RootMigrations: Use canonical migrations
  Makefile->>Diesel: Run or revert migrations
  Diesel->>Makefile: Generate schema output
  nvisy-postgres->>RootMigrations: Embed migrations during build
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: embedding migrations directly from the single root migrations directory.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (2 skipped: 2 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/single-migrations-dir

Comment @coderabbitai help to get the list of available commands.

@martsokha martsokha self-assigned this Sep 4, 2026
@martsokha
martsokha merged commit 7fac7a0 into main Sep 4, 2026
9 checks passed
@martsokha
martsokha deleted the chore/single-migrations-dir branch September 4, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore maintenance, dependency updates, code cleanup postgres ORM, models, queries, migrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant