Skip to content

Fix hardcoded references to conf directory #1

Closed

Description

@benmccann

EbeanDynamicEvolutions has hardcoded references to the conf directory:

File evolutions = environment.getFile("conf/evolutions/" + key + "/1.sql");
Files.createDirectory(environment.getFile("conf/evolutions/" + key));

Activity

  1. felipebonezi commented on May 13, 2021

    @felipebonezi
    Contributor

    @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?

    image

  2. benmccann commented on May 13, 2021

    @benmccann
    ContributorAuthor

    I haven't used Play in years. I'm afraid my memory from 2014 is rather fuzzy

  3. mkurz commented on May 13, 2021

    @mkurz
    Member

    @felipebonezi Look at this code from Play:

    val evolution = {
      // First try a file on the filesystem
      val filename = Evolutions.fileName(db, paddedRevision)
      environment.getExistingFile(filename).map(_.toURI)
    }.orElse {
      // If file was not found, try a resource on the classpath
      val resourceName = Evolutions.resourceName(db, paddedRevision)
      environment.resource(resourceName).map(url => url.toURI)
    }

    Evolutions.fileName(db, revision) also tries to access the evolutions file in the hardcoded conf folder.

      /**
       * Default evolutions directory location.
       */
      def directoryName(db: String): String = s"conf/evolutions/${db}"
    
      /**
       * Default evolution file location.
       */
      def fileName(db: String, revision: Int): String = s"${directoryName(db)}/${revision}.sql"
    
      def fileName(db: String, revision: String): String = s"${directoryName(db)}/${revision}.sql"

    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.

  4. mkurz commented on May 13, 2021

    @mkurz
    Member

    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.

  5. mkurz commented on Oct 13, 2026

    @mkurz
    Member

    Coming back to this: the path has been configurable since Play Ebean 7.0.0.

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions