Ankeet's backend garden

data-loading-spring

two ways to do it

  • using plain ol' sql scripts
  • using inbuilt [repository] support

sql

  • make sure you've these scripts which create the database and load some data using insert statements
  • [spring] automatically looks for different file names; check it out here
  • also make these properties false so as to prevent the default jpa behaviour of spring

opinions

  • I for one love this way as I've the complete control on what's going and not
  • I can have these files for dev and qa environment and make it easier to have a base set of data
  • it's easy to export a dump from the original prod database and check-in the repo with a trimmed version
    • awesome, no need to manually write the DDL and DML queries
  • but it might be a problem if db changes - which is NEVER I assume, as it would be foolhardy to develop on one and deploy on another

using repository in an @Component bean

  • add a method and annotate it as @PostConstruct which will execute on startup
  • then autowire the repository and start adding objects
spring.datasource.initialization-mode=always
spring.jpa.hibernate.ddl-auto=none

Referred in

data-loading-spring