DEV Community

Robert Rees
Robert Rees

Posted on

Nomad Migration Manager

Nomad is a migration manager written in Python. It is simple compared to things like Alembic, relying on plain SQL script files with accompanying metadata to control sequencing.

One of Nomad's most unusual features is that it only provides "up" migrations rather than the conventional up and down changes.

In Nomad an "down" migration is simply an "up" migration that takes you to a previous structure. This insight should be copied more as it is relatively rare that you ever do a down migration. In my experience, they tend to happen in development when you realise you've made a mistake and reset the database before correcting the migration and re-applying. In Nomad when this situation occurs you would create a new migration to correct the mistake and then apply the whole migration sequence to production.

I find this admirably transparent but for a lot of people keeping "mistakes" in the codebase would make them very unhappy.

Nomad keeps the database connection details in an ini file that can read environment variables so really you probably want to use a dotenv file excluded from source control to provide the connection details.

Once you done this the Nomad CLI provides a pretty simple interface to create new migrations (with optional dependencies), apply an individual migration or apply all due migrations.

Because Nomad relies on just executing the SQL file associated with the migration it is relatively feature-light and creating migrations simply means writing the appropriate DDL SQL for your database (there are no portability features here despite using SQLAlchemy under the hood).

The only problem I've had using Nomad is really getting the initial configuration to work. After that it has been pretty smooth sailing and the resulting SQL has been much more shareable between my hobby projects than other DSL-based migration tools.

API Trace View

Struggling with slow API calls? 👀

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay