Skip to content

RFC #4 - Patterns for dealing with migration bloat #458

Open
@panta82

Description

@panta82

As my application grows, so does the number of migrations. I am already up to 50, and the big refactoring I am doing now will produce 10-15 new migrations on top of that.

So I started looking for ways to somehow organize these migrations and reduce the bloat in the migrations folder.

The first thing I tried was to group these big features into scopes, and use them as "migration groups" of sorts. That didn't quite work out. migrate all will run scopes in an arbitrary order one after another, which means I can't really use them to modify the same database with cross-cutting concerns. Scopes are really only useful for either completely isolated features, or different databases.

I also considered packing more changes into a single migration, using some kind of async chaining pattern. Unfortunately, I use MySQL which doesn't have DDL transactions. So if anything breaks, I'm stuck with an inconsistent state that I have to resolve manually. The best way to use db-migrate is indeed to create a new migration for every step, which doesn't help the bloat problem.

Another option would be to rewrite some older migrations that are doing duplicate work (eg. create table, mutate table, add column, remove column...) into a single migration. But that sounds like a lot of manual fiddly bug-causing work.

So in the end, I think I'll probably just preface my new migrations with the feature name (eg. 20170118141857-big_refactoring-add_table_x) and keep adding them as I'm used to.

Before that though, I figured I should ask. Is there some option or pattern I am missing? What is the recommended best practice for dealing with accumulated migration bloat?


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions