2016-11-14 148 views
0

数据库迁移我有这样的范例项目HERE与Neo4j的春季

在样本数据,我尝试使用Flyway来实现与Neo4j的数据库数据库迁移。我可以用H2数据库创建并插入普通SQL(我在示例项目中使用了H2数据库),但我不知道如何使用Neo4j graphdatabase实现它。

我需要在应用程序启动时初始化数据。这是我尝试设置我的移民代码:

public class V1_1__InitMaster implements SpringJdbcMigration { 
public void migrate(JdbcTemplate jdbcTemplate) throws Exception { 
    /* 
    //Example using h2 database 
    jdbcTemplate.execute("CREATE TABLE Unit (" 
      + "code VARCHAR(30)," 
      + "name VARCHAR(30)," 
      + "value DOUBLE" 
      + ");"); 

    jdbcTemplate.execute("INSERT INTO Unit ('ft','Feet',1);"); 

    //How I can save my init data to neo4j database in here? 
    for(String[] unitString : initDataMaster.unitList){ 
     //I got list unitList here 
    } 
    */ 
} 
} 

我读这Page关于迁徙路线,可与Neo4j的管理数据库迁移,而我看起来有些页面,大约有春节和Neo4j的迁飞整合解释。

我问的是,如何保存我的初始化数据并使用Flyway来管理它并将其与Neo4j和Spring集成?

+1

我不知道迁徙路线迁移,但是你看https://github.com/fbiville/liquigraph?它受Liquibase的启发,特定于Neo4j迁移。 – digx1

+0

是的,我是。但liquigraph缺乏我认为的文档,而且我需要Java配置+ java示例代码。它很难理解文档。起初,我想使用它,但在检查文档并尝试深入观察后,我不确定如何使用它。 –

+0

我认为这是合理的记录:http://fbiville.github.io/liquigraph/latest/index.html。有什么更详细的,你需要吗? – digx1

回答

4

编辑

一个新的春天开机启动(为Liquigraph 3.X仅)已被引入到与Spring引导工作充分,在结尾的链接仍然按照现在的参考。

所有你需要做的就是用起动机liquigraph-spring-boot-starterspring-boot-starter-jdbc,启用自动配置(通过@EnableAutoConfiguration),并宣布提供application.properties至少liquigraph.url)。

最初的回答

Liquigraph是专为Neo4j的管理迁移。 根据您要支持的Neo4j版本,您将选择Liquigraph 2.x(用于Neo4j 2.x)或Liquigraph 3.x(用于Neo4j 3.x)。

与Spring的集成非常简单,您可以将DataSourceJDBC URI(和用户/密码)传递给配置生成器,并以编程方式触发迁移运行。

该文档描述了here(不是特定于Spring,这是以编程方式运行迁移的不可知方式)。

的配置看起来是这样的(前提是你定义DataSource这个配置类的地方访问):

@Configuration 
class MigrationConfiguration { 

    @Bean 
    public MethodInvokingFactoryBean liquigraph(org.liquigraph.core.configuration.Configuration liquigraphConfig) { 
     MethodInvokingFactoryBean method = new MethodInvokingFactoryBean(); 
     method.setTargetObject(new Liquigraph()); 
     method.setTargetMethod("runMigrations"); 
     method.setArguments(new Object[] {liquigraphConfig}); 
     return method; 
    } 

    @Bean 
    public org.liquigraph.core.configuration.Configuration configuration(DataSource dataSource) { 
     return new ConfigurationBuilder() 
      .withDataSource(dataSource) 
      .withMasterChangelogLocation("changelog.xml") 
      .withRunMode() 
      .build(); 
    } 
} 

完整的例子是在这里:https://github.com/fbiville/liquigraph-spring-boot-example

+0

哇,这真酷!它是否也支持JPA QueryBuilder?如果JPA queryBuilder也支持它,那将会非常棒。 changelog只支持XML吗?有没有关于Java类变更日志的例子? –

+0

目前首选的方法是使用XML。 您可以直接定义Liquigraph模型的Java实例(请参阅https://github.com/fbiville/liquigraph/blob/master/liquigraph-core/src/main/java/org/liquigraph/core/model/Changelog.java)但不建议这样做。 尚未计划JPA QueryBuilder支持。我们可以看看我们将来是否可以与JCypher进行整合(https://github.com/Wolfgang-Schuetzelhofer/jcypher/wiki/Query-DSL-Expressions)。 – Rolf

+0

啊,好吧。我将尝试写入XML上的所有数据。非常感谢你@Rolf –