We have an “old” project with more than 350 evolutions. Is there a way to organize these files to multiple directories? Like 1-50/51-100/ etc? It is really hard at this point to find out what is the last “magic number” and also not really user-friendly in most editors to list 300-500 files… I don’t want to modify them, just organize to subdirs.
Not sure about sub-foldering. As an alternative, you might consider consolidating evolutions 1-100, 101-200 and so on. This will reduce the number of files, and make the setup of new database quicker.
This question is a perfect use case for a custom implementation of an EvolutionsReader (which still needs documentation):
I copied an example from an existing project of mine (also have a look at the code comments with links to similiar resources):
package my.organisation.evolutions;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Singleton;
import com.typesafe.config.Config;
import play.Environment;
import play.Logger;
import play.api.db.evolutions.Evolutions;
import play.api.db.evolutions.ResourceEvolutionsReader;
import scala.Option;
import scala.compat.java8.OptionConverters;
/**
* From
* https://github.com/playframework/playframework/blob/2.8.0/persistence/play-jdbc-evolutions/src/main/scala/play/api/db/evolutions/EvolutionsApi.scala#L522-L558
*
* <p>Also see: https://github.com/playframework/playframework/issues/2813
* https://gist.github.com/mkurz/061d413715f004c8c963
*/
@Singleton
public class MyEvolutionsReader extends ResourceEvolutionsReader {
private final Environment environment;
private final Config config;
@Inject
public MyEvolutionsReader(final Environment environment, final Config config) {
this.environment = environment;
this.config = config;
}
@Override
public Option<InputStream> loadResource(final String db, final int revision) {
// here you need to implement your logic like if revision 1-50, load the script from the the "50" folder, etc.
}
}
You need to override the loadResource method, which looks up the evolution file and returns it as an input stream. IMHO that is exactly what you need.