Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
manueljordan opened this issue Jul 3, 2023 · 5 comments
Labels
type: documentation A documentation update
Milestone

Comments

@manueljordan
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 3, 2023
@wilkinsona
Copy link
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.

@wilkinsona wilkinsona added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 3, 2023
@wilkinsona wilkinsona added this to the 2.7.x milestone Jul 3, 2023
@wilkinsona wilkinsona 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 Jul 3, 2023
@manueljordan
Copy link
Author

manueljordan commented Jul 3, 2023

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

@manueljordan
Copy link
Author

manueljordan commented Jul 3, 2023

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 ...

@wilkinsona
Copy link
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.

@manueljordan
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

3 participants