Help regarding auto seeding of db tables from the auto generated schema

Have a spring boot application where i am using Spring Data JPA and creating the db schema automatically using the ORM. Now my requirement is to automatically run the schema .sql file to create tables and relationships when building and deploying the project the project . Need some help. Here is my application config:
spring.application.name=RentalNoticeSystem

# Datasource configuration
spring.datasource.url=jdbc:mariadb://localhost:3306/rentalnotice
spring.datasource.username=root
spring.datasource.password=1234qwer

#spring.datasource.username=noticepro
#spring.datasource.password=1234qwer

spring.datasource.driver-class-name=org.mariadb.jdbc.Driver

# JPA configuration
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true
spring.jpa.properties.javax.persistence.database-product=MariaDB
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect

#Hibernate Logging
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE


# Generate the schema DDL to a file (Schema Auto-Generation)
spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=generated-schema.sql
spring.jpa.properties.javax.persistence.schema-generation.scripts.drop-target=generated-drop.sql


#Server Context Path for Embedded Tomcat / Jboss External tomcat will not fetch this, it will fetch from WEB-INF/jboss-web.xml
# server.servlet.context-path=/noticepro

#Custom Error Page
server.error.whitelabel.enabled=false
server.error.include-message=always
server.error.include-stacktrace=always

# Custom error path
server.error.path=/error
spring.application.name=RentalNoticeSystem

# Datasource configuration
spring.datasource.url=jdbc:mariadb://localhost:3306/rentalnotice
spring.datasource.username=root
spring.datasource.password=1234qwer

#spring.datasource.username=noticepro
#spring.datasource.password=1234qwer

spring.datasource.driver-class-name=org.mariadb.jdbc.Driver

# JPA configuration
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true
spring.jpa.properties.javax.persistence.database-product=MariaDB
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect

#Hibernate Logging
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE


# Generate the schema DDL to a file (Schema Auto-Generation)
spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=generated-schema.sql
spring.jpa.properties.javax.persistence.schema-generation.scripts.drop-target=generated-drop.sql


#Server Context Path for Embedded Tomcat / Jboss External tomcat will not fetch this, it will fetch from WEB-INF/jboss-web.xml
# server.servlet.context-path=/noticepro

#Custom Error Page
server.error.whitelabel.enabled=false
server.error.include-message=always
server.error.include-stacktrace=always

# Custom error path
server.error.path=/error
5 Replies
JavaBot
JavaBot3mo ago
This post has been reserved for your question.
Hey @BigWiz! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here. 💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
galdino
galdino3mo ago
Have you ever heard about Flyway? It has a "concept" called afterMigrate. This could help you with that... Here's an example: https://github.com/galdino/ufood-api/blob/main/src/main/resources/db/testdata/afterMigrate.sql
GitHub
ufood-api/src/main/resources/db/testdata/afterMigrate.sql at main ·...
Rest API with Spring, Spring Boot, Spring Data JPA - galdino/ufood-api
BigWiz
BigWizOP3mo ago
heard it for the first time, found a good baeldung tutorial, and tried it out. will implement in my own app within sometime, thanks for letting me know about this awesome piece of software.
JavaBot
JavaBot3mo ago
If you are finished with your post, please close it. If you are not, please ignore this message. Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
JavaBot
JavaBot3mo ago
Post Closed
This post has been closed by <@146662188122243072>.

Did you find this page helpful?