Database Initialization Using Script

Slack Discussion Repositories https://github.com/terawarehouse/terawarehouse-catalog https://github.com/terawarehouse/terawarehouse-react Th...


Slack Discussion

Repositories
There are times when we want to use a SQL script to generate the schema and populate the database. Personally, I use the code which we previously discussed as it triggers notifications which you might have set in entity’s create or update method. But sometimes, you might already have a large chunk of sample data from excel exported from another system that you need to do some processing and that is when this method is useful.

Going back to the project we first need to change the value of spring.jpa.hibernate.ddl-auto to validate.
[open application.properties]

This instructs Spring not to auto-generate the database schema from the entity classes, rather use the schemal.sql and data.sql files located in src/main/resources folder.

Let’s take a look at the SQL files.
[open schema.sql]

Here we defined the tables which mapped to the entity classes.
[open data.sql]

Needless to say, this is where we insert records.

Now let’s run the application. As expected the tables are created and 1 row of a category is inserted.

COMMENTS

mas template
Name

amazon,1,angular,8,bigdata,2,business,1,course-spring,27,courses,6,database,4,docker,3,java,50,kafka,1,keycloak,4,microservices,5,mysql,1,neworking,1,nosql,2,php,1,pinned,2,react,3,server management,7,shared drive,1,spring,7,synology,1,troubleshooting,2,web,1,wordpress,1,
ltr
item
toztech: Database Initialization Using Script
Database Initialization Using Script
https://i.ytimg.com/vi/C9GJG7CEKe8/0.jpg
https://i.ytimg.com/vi/C9GJG7CEKe8/0.jpg
toztech
https://toztech.blogspot.com/2019/06/database-initialization-using-script.html
https://toztech.blogspot.com/
https://toztech.blogspot.com/
https://toztech.blogspot.com/2019/06/database-initialization-using-script.html
true
2554149350007112447
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content