You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@benmccann@schmitch hey guys, I want to fix this problem but I'm not understanding how to get application conf folder and how to write some tests. Can you help me understand?
I was thinking to use Environment.rootPath() to get application root folder and then concat with /conf.
Do you think that is a good approach?
valevolution= {
// First try a file on the filesystemvalfilename=Evolutions.fileName(db, paddedRevision)
environment.getExistingFile(filename).map(_.toURI)
}.orElse {
// If file was not found, try a resource on the classpathvalresourceName=Evolutions.resourceName(db, paddedRevision)
environment.resource(resourceName).map(url => url.toURI)
}
however if that files does not exist if falls back to Evolutions.resourceName(db, revision) which does not include the hardcoded conf/ prefix (also here the resource gets loaded via environment.resource(...) which loads the resource from the classpath).
I think that is the only way to solve this problem here. There is no helper method which gives you the conf folder. That's because in Play you can disable the PlayLayoutPlugin and then there is no conf folder anymore, but instead the maven style folder structure is used and src/main/resources is used instead.
Also, because (depending if PlayLayoutPlugin is enable dor not) the conf folder or src/main/resources gets added to the classpath, so that fallback should be able to read the file, no matter where it is located.
made Play Ebean write the generated script with Play's own helpers and the play.evolutions[.db.<name>].path setting (playframework/playframework#11917), so it follows the configured location of the evolution scripts.
Looking into it again showed two more problems, which #931 addresses (also in 8.x and 7.x):
With an absolute path, Play Ebean wrote the script relative to the application's root folder, where Play didn't find it. That's fixed now.
In a project that disables Play's layout, the generated script ends up in conf, which doesn't get packaged, and in dev and test mode it takes precedence over a script in src/main/resources. The docs now describe a workaround, and Generated evolution scripts in projects without Play's layout #930 tracks proper support.
If you still run into problems with where the generated scripts end up, please open a new issue.
Activity
felipebonezi commentedon May 13, 2021
@benmccann @schmitch hey guys, I want to fix this problem but I'm not understanding how to get application
conffolder and how to write some tests. Can you help me understand?I was thinking to use
Environment.rootPath()to get application root folder and then concat with/conf.Do you think that is a good approach?
benmccann commentedon May 13, 2021
I haven't used Play in years. I'm afraid my memory from 2014 is rather fuzzy
mkurz commentedon May 13, 2021
@felipebonezi Look at this code from Play:
Evolutions.fileName(db, revision) also tries to access the evolutions file in the hardcodedconffolder.however if that files does not exist if falls back to
Evolutions.resourceName(db, revision)which does not include the hardcodedconf/prefix (also here the resource gets loaded viaenvironment.resource(...)which loads the resource from the classpath).I think that is the only way to solve this problem here. There is no helper method which gives you the conf folder. That's because in Play you can disable the
PlayLayoutPluginand then there is noconffolder anymore, but instead the maven style folder structure is used andsrc/main/resourcesis used instead.mkurz commentedon May 13, 2021
Also, because (depending if
PlayLayoutPluginis enable dor not) theconffolder orsrc/main/resourcesgets added to the classpath, so that fallback should be able to read the file, no matter where it is located.mkurz commentedon Oct 13, 2026
Coming back to this: the path has been configurable since Play Ebean 7.0.0.
play.evolutions[.db.default].pathconfig for dynamic evolutions #387made Play Ebean write the generated script with Play's own helpers and the
play.evolutions[.db.<name>].pathsetting (playframework/playframework#11917), so it follows the configured location of the evolution scripts.Looking into it again showed two more problems, which #931 addresses (also in 8.x and 7.x):
conf, which doesn't get packaged, and in dev and test mode it takes precedence over a script insrc/main/resources. The docs now describe a workaround, and Generated evolution scripts in projects without Play's layout #930 tracks proper support.If you still run into problems with where the generated scripts end up, please open a new issue.