diff --git a/src/main/java/com/loafle/overflow/JdbcConfiguration.java b/src/main/java/com/loafle/overflow/JdbcConfiguration.java index f3adcf4..d724549 100644 --- a/src/main/java/com/loafle/overflow/JdbcConfiguration.java +++ b/src/main/java/com/loafle/overflow/JdbcConfiguration.java @@ -5,8 +5,11 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.jdbc.datasource.init.DataSourceInitializer; +import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; @@ -76,4 +79,17 @@ public class JdbcConfiguration implements TransactionManagementConfigurer { public EntityManager entityManager() { return entityManagerFactory().getObject().createEntityManager(); } + + @Bean + public DataSourceInitializer dataSourceInitializer(DataSource dataSource) { + ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); + databasePopulator.addScript(new ClassPathResource("/init.sql")); + databasePopulator.setIgnoreFailedDrops(true); + + DataSourceInitializer initializer = new DataSourceInitializer(); + initializer.setDataSource(dataSource); + initializer.setDatabasePopulator(databasePopulator); + + return initializer; + } } diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql new file mode 100644 index 0000000..9af6fd4 --- /dev/null +++ b/src/main/resources/init.sql @@ -0,0 +1 @@ +--insert into meta_member_status (id, name) values (7, 'FFFFF'); \ No newline at end of file