migrations icon indicating copy to clipboard operation
migrations copied to clipboard

Custom migration directory

Open ilyakaznacheev opened this issue 5 years ago • 4 comments

It's very rare in big projects, that migration files are located in the same directory as an executable file or in the root directory. If the project implements the standard layout or is just big enough to have many parts and sub packages, migration files are normally stored in some place, far away from root or cmd directory.

I've implemented custom folder support on my project, that discovers migration files by the path, provided with the CLI parameter. But I would like to see and find it very useful to have such option out-of-the-box.

If it doesn't contradict the main idea of the library, I would like to implement it as an optional CLI argument, that defines a custom path to the migration directory.

ilyakaznacheev avatar Apr 27 '19 18:04 ilyakaznacheev

We have https://godoc.org/github.com/go-pg/migrations#Collection.DiscoverSQLMigrations that allows to scan any directory for SQL migrations with few lines of code. I would not add those lines to the lib because it adds a dependency on the flags package and different people have different requirements.

So unless I miss something and it is more complicated - thanks, but no.

vmihailenco avatar Apr 28 '19 06:04 vmihailenco

The point about a flag lib sounds reasonable. Then I would like to add an example of a custom directory discovery to example. It's a really nice feature but not so well documented, so it took me to read all the sources to understand how I can use this feature without any breakage.

It also gives me the idea that the library needs a list of features like pg has.

ilyakaznacheev avatar Apr 28 '19 09:04 ilyakaznacheev

I have similar question. How can I use custom migration directory, where not only sql, but go files are placed? For example, I want that command "go run *.go create add email to users" creates migration file in special folder "./migrations" not in root folder. Can use provide such option, please?

Ragnar-BY avatar May 21 '21 12:05 Ragnar-BY

DiscoverSQLMigrations does not discover the .go files. Is there any way to discover the go file as well.

ohmpatel1997 avatar Nov 15 '21 14:11 ohmpatel1997