Skip to content

Document that scripts for database initialization are optional by default and how they can be made mandatory #36176

Closed

Description

@manueljordan

Hello

Pls, read the following SO post first

Could be consider to add a new Application Property such as spring.sql.init.missing.scripts with enum values such as ignore (as default) error in case that the expected sql files are not found?

To be honest I expected receive a kind of error, but it did not happen. And if the comments on SO post are correct, it is not indicated at 9.3. Initialize a Database Using Basic SQL Scripts

Thanks for your understanding

Activity

  1. added
    status: waiting-for-triage
    on Jul 3, 2023
  2. wilkinsona commented on Jul 3, 2023

    @wilkinsona
    Member

    We probably need to document this better. You can make the scripts mandatory by configuring spring.sql.init.schema-locations and spring.sql.init.data-locations with values that don't use the optional: prefix.

  3. added
    type: documentation
    and removed
    status: waiting-for-triage
    on Jul 3, 2023
  4. added this to the 2.7.x milestone on Jul 3, 2023
  5. changed the title [-]Consider to add new Application Property to handle scenario on missing sql scripts files[/-] [+]Document that scripts for database initialization are optional by default and how they can be made mandatory[/+] on Jul 3, 2023
  6. manueljordan commented on Jul 3, 2023

    @manueljordan
    Author

    Thanks for the feedback

    Correct, I have confirmed that spring.sql.init.schema-locations and spring.sql.init.data-locations makes the scripts files mandatory

    I have confirmed that optional: makes the scripts files optional, it was tested when the file scripts do not exist as follows

    spring.sql.init.schema-locations=optional:/com/manuel/jordan/mysql/v2/schema-mysqlx.sql
    spring.sql.init.data-locations=optional:/com/manuel/jordan/mysql/v2/data-mysqlx.sql
    

    About either optional or optional:, it is not mentioned at 9.3. Initialize a Database Using Basic SQL Scripts

    Just as an observation, take in consideration in indicate explicitly if the classpath prefix is mandatory or not, I have tested with and without this prefix and the app works too. This test was accomplished even for with and without a jar execution, I mean, through mvn spring-boot:run and java -jar respectively - therefore 4 scenarios.

    • with classpath for not jar app execution
    • with classpath for jar app execution
    • without classpath for not jar app execution
    • without classpath for jar app execution

    So theoretically at a first glance classpath is not mandatory, but ... according with this comment (written by you) in the following post:

    it seems is mandatory. A clarification about your comment for the Reference documentation is valuable for the community.
    As usual I use the classpath prefix.

    Thanks for your understanding

  7. manueljordan commented on Jul 3, 2023

    @manueljordan
    Author

    Btw the optional: prefix does not appear for both Application Properties as follows

    image

    and

    image

    Not sure if is related with SB or with STS4 ...

  8. wilkinsona commented on Jul 3, 2023

    @wilkinsona
    Member

    That's a tooling issue. There's no way for the tooling to know what prefixes will work as it depends on the resource loader and any protocol resolvers. optional: will always work as it's a feature of AbstractScriptDatabaseInitializer rather than resource resolution.

  9. manueljordan commented on Jul 3, 2023

    @manueljordan
    Author

    Thanks for confirmation, I am going to report this situation to STS4

  10. modified the milestones: 2.7.x, 2.7.15 on Aug 8, 2023
  11. added a commit that references this issue on Aug 8, 2023
    db0ab9f
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

    type: documentation

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions