pressly / goose

A database migration tool. Supports SQL migrations and Go functions.
http://pressly.github.io/goose/
Other
7.1k stars 521 forks source link

Support up and down code in separate files. #374

Open nikolay opened 2 years ago

nikolay commented 2 years ago

Relying on comments and mixing code that both creates and destroys in one file is not ideal. Many frameworks support filename schemes such as <MIGRATION_ID>.up.sql and <MIGRATION_ID>.down.sql, so, ideally, Goose should support it, too.

mfridman commented 2 years ago

Indeed we have to parse out the statements, but this was an explicit decision made a long long time ago.

This hasn't really been an issue so far (at least based on all the teams I've worked on that used goose).

Maybe subjective, but I prefer a single migration file that captures both up and down. It looks cleaner when you have a lot of migrations.

nikolay commented 2 years ago

What if I want to automatically extract the migration? Then I need to parse the file myself. In general, when the files are sorted, they will one after another, so, it's no less clean looking into the directory. Other frameworks do use separate files and the ones that use a single file are influenced by Ruby, but in Ruby language constructs are used, no comments, which are not even standard across migration frameworks that use comments! I am only saying allow both so different people will use different approaches.

JasonPMC commented 2 years ago

For what it's worth, one of the reasons we choose Goose was because it halved the number of files we have to deal with.

nikolay commented 2 years ago

@JasonPMC Absolutely all recent database migration frameworks use a single file per step! A great differentiator would be giving users an option to pick though!

nightlord189 commented 11 months ago

I agree, it will be more convenient than single file.

nikolay commented 11 months ago

@nightlord189 Convenient in what sense? What if you mess up the markup and migration goes wrong executing both directions?!

mfridman commented 11 months ago

Another consideration is upstream tools that rely on goose migrations having a known file structure. One popular tool that comes to mind is https://github.com/sqlc-dev/sqlc, they expect this file format:

https://docs.sqlc.dev/en/stable/howto/ddl.html#goose