From e1f1c06b5919524923a9e7be428775a6dc8e9de2 Mon Sep 17 00:00:00 2001 From: insanity Date: Sun, 25 Jun 2017 17:16:15 +0900 Subject: [PATCH] init.sql --- .../com/loafle/overflow/JdbcConfiguration.java | 16 ++++++++++++++++ src/main/resources/init.sql | 1 + 2 files changed, 17 insertions(+) create mode 100644 src/main/resources/init.sql 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