Skip to content

[BugFix] Add spring.sql.init auto-initialization for MySQL and PostgreSQL (#4340) - #4503

Open
zhang-arvin wants to merge 1 commit into
apache:devfrom
zhang-arvin:fix/issue-4340-table-not-exists
Open

[BugFix] Add spring.sql.init auto-initialization for MySQL and PostgreSQL (#4340)#4503
zhang-arvin wants to merge 1 commit into
apache:devfrom
zhang-arvin:fix/issue-4340-table-not-exists

Conversation

@zhang-arvin

Copy link
Copy Markdown

Description

This PR fixes issue #4340 by adding spring.sql.init auto-initialization for MySQL and PostgreSQL.

When the application starts and the target table does not exist, Spring Boot can automatically create tables based on the schema.sql configuration. This ensures that the required database tables are created automatically during the first startup.

Changes

  • Added spring.sql.init.mode=always configuration for MySQL and PostgreSQL profiles
  • Added schema initialization SQL files for automatic table creation

Testing

  • Verified that tables are auto-created on first startup with MySQL
  • Verified that tables are auto-created on first startup with PostgreSQL

…izing schema

Add schema and data SQL files for MySQL and PostgreSQL to the classpath resources,
and configure Spring Boot's sql.init to auto-initialize the database on startup.

Root cause: When using MySQL or PostgreSQL as the datasource, SpringProperties.java
only configured the datasource connection but did not set up spring.sql.init
properties. This caused tables to never be auto-created, resulting in
'Table does not exist' errors on first startup.

Changes:
- Add schema-mysql.sql, data-mysql.sql to resources/db/
- Add schema-pgsql.sql, data-pgsql.sql to resources/db/
- Update SpringProperties.java to configure spring.sql.init for MySQL and PostgreSQL

Closes apache#4340
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant