Package com.example.demo.db
Class SchemaFixRunner
java.lang.Object
com.example.demo.db.SchemaFixRunner
- All Implemented Interfaces:
org.springframework.boot.CommandLineRunner
@Component
public class SchemaFixRunner
extends Object
implements org.springframework.boot.CommandLineRunner
A one-time component designed to fix common database schema
issues encountered when using JPA with certain database dilects, it
uses alot of spring boots code so check their doc to learn more
-
Constructor Summary
ConstructorsConstructorDescriptionSchemaFixRunner(org.springframework.jdbc.core.JdbcTemplate jdbc) Constructs the SchemaFixRunner and injects the necessaryJdbcTemplate. -
Method Summary
-
Constructor Details
-
SchemaFixRunner
public SchemaFixRunner(org.springframework.jdbc.core.JdbcTemplate jdbc) Constructs the SchemaFixRunner and injects the necessaryJdbcTemplate.- Parameters:
jdbc- The Spring JDBC template.
-
-
Method Details
-
run
Executes the schema fix logic when the Spring Boot application starts up.The execution involves: 1. Checking the primary key status to skip if already
AUTO_INCREMENT. 2. Identifying and dropping any existing foreign key constraints on the child table. 3. Dropping any residual indexes left behind after the foreign key removal. 4. Modifying the parent table's primary key (`id`) to beAUTO_INCREMENT. 5. Recreating the foreign key constraint on the child table, ensuring data integrity.- Specified by:
runin interfaceorg.springframework.boot.CommandLineRunner- Parameters:
args- Command line arguments passed to the application.
-