I followed many links like Spring Batch Framework - Auto create Batch Table and https://docs.spring.io/spring-boot/docs/2.0.0.M7/reference/htmlsingle/#howto-initialize-a-spring-batch-database, but that doesn't satisfy my requirement
In Spring Boot 2.0, how we can call sql file (created manually and have all the schema details) so that Spring Batch can create it manually for us and if schema is already present then skip the execution ?
<!-- Create meta-tables -->
<jdbc:initialize-database data-source="dataSource">
<jdbc:script location="classpath:hsqldb/initial-query.sql" />
<jdbc:script location="org/springframework/batch/core/schema-drop-hsqldb.sql" />
<jdbc:script location="org/springframework/batch/core/schema-hsqldb.sql" />
</jdbc:initialize-database>
I am looking to do 1. If Schema already present then don't create any tables 2. If schema is not present then create the tables
Project structure
DROP TABLE IF EXISTS report;
CREATE TABLE report (
id INT NOT NULL PRIMARY KEY,
date DATETIME,
impression BIGINT,
clicks INT,
earning DECIMAL(12,4)
)ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
application.properties
# Data Source
spring.datasource.url=jdbc:mysql://localhost:3306/spring_batch
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
# SPRING BATCH (BatchProperties)
# Database schema initialization mode.
spring.batch.initialize-schema=always
# Execute all Spring Batch jobs in the context on startup.
#spring.batch.job.enabled=false
# Path to the SQL file to use to initialize the database schema.
spring.batch.schema=classpath:schema-all.sql