Grails hbase-如何在不删除表的情况下更改表结构

Grails hbase-如何在不删除表的情况下更改表结构,grails,groovy,nosql,hadoop,hbase,Grails,Groovy,Nosql,Hadoop,Hbase,我使用grails-1.3.2和插件 有时我需要更改表结构(添加新表或列)。 我已经创建了Car表: class Car{ static belongsTo = [user:User] String color String model //..... static constraints = { } } 但当我想创建汽车对象时: def create = { Car car = new Car() car.p

我使用grails-1.3.2和插件

有时我需要更改表结构(添加新表或列)。 我已经创建了Car表:

class Car{
    static belongsTo = [user:User]

    String color
    String model
    //.....

    static constraints = {
    }
}
但当我想创建汽车对象时:

def create = {
        Car car = new Car()
        car.properties = params
        car.save(flush: true)        
 }
我得到了以下例外:

ERROR gorm.SavePersistentMethod  - APP_CAR
org.apache.hadoop.hbase.TableNotFoundException: APP_CAR
在我用createdrop运行应用程序之后,一切都开始正常工作了。。 但我不能在每次更改后删除所有数据, 我认为插件必须做所有的更新

所以,我正在寻找changind tables结构在不删除表的情况下继续运行应用程序的方法


如果有人知道这个解决方案,请提供帮助。

Grails不会自动更新您的表,如果它在生产中自动删除一列会怎么样?也许那不是你想要的

有一个数据库迁移插件可以做到这一点,这里有一个很好的解释。请注意,您需要使用grailsprod,而不是直接在链接中使用,否则它将仅在开发模式下运行。该链接在其命令中不显示prod


官方链接是,spring源代码的博客是。

数据库迁移插件将不起作用,因为它只适用于hibernate。 您需要在插件源代码中做一些更改。HBasePluginSupport.grovy

static doWithApplicationContext = {ApplicationContext applicationContext ->
    LOG.debug("Closure HBasePluginSupport.doWithApplicationContext{} invoked with arg $applicationContext")

    assert !PluginManagerHolder.getPluginManager().hasGrailsPlugin("hibernate"),"hibernate plug-in conflicts with gorm-hbase plug-in"

    // Read data source configuration, setting defaults as required
    def dataSource = application.config.dataSource
    // TODO write tests for this <--- Even maybe figure out if this is ever invoked
    if (!dataSource) dataSource = new HBaseDefaults()

    def dbCreate = dataSource?.dbCreate
    if (!dbCreate) dbCreate = "create-drop"
    LOG.debug("Data Source configured with dbCreate set to $dbCreate")

    // TODO Complete dbCreate related processing
    if (dbCreate?.toUpperCase()?.equals("CREATE-DROP")) {
        def createIndexedTables = dataSource?.indexed
        LOG.debug ("Flag createIndexedTables set to $createIndexedTables")
        def tableManager = HBaseLookupUtils.getBean("hbase.table.manager")

        tableManager.createSequenceTable()
        tableManager.createReferenceTable()

        application.domainClasses.each {domainClass ->
            LOG.debug("Adding table for Domain Class $domainClass")
            tableManager.createDomainTable(domainClass, createIndexedTables)
        }

        LOG.debug("List of all store found :")
        tableManager.getTableNames().each {tn ->
            LOG.debug("- $tn")
        }
    } else if (dbCreate?.toUpperCase()?.equals("UPDATE")) {
        def createIndexedTables = dataSource?.indexed
        def tableManager = HBaseLookupUtils.getBean("hbase.table.manager")
        def existingTables = tableManager.getTableNames();

        application.domainClasses.each {domainClass ->
            LOG.debug("Domain Class $domainClass")
            def tableDesc = new HTableDescriptor(HBaseNameUtils.getDomainTableName(domainClass))
            if (!existingTables.contains(tableDesc.getNameAsString())) {
                tableManager.createDomainTable(domainClass, createIndexedTables)
                LOG.debug("Adding table for Domain Class $domainClass")
            }
        }
    }

    application.domainClasses.each {domainClass ->
        LOG.debug("Adding dbms related methods to Domain Class $domainClass")
        def domainClassManager = new HBaseDomainClassManager()
        domainClassManager.createQueryMethods(domainClass)
        domainClassManager.createPersistenceMethods(domainClass)
        domainClassManager.addLazyLoadingSupport(domainClass)
        domainClassManager.addDynamicFinders(domainClass)
    }
}
static doWithApplicationContext={ApplicationContext ApplicationContext->
LOG.debug(“用arg$applicationContext调用的Closure HBasePluginSupport.doWithApplicationContext{}”)
assert!PluginManager.getPluginManager().hasGrailsPlugin(“hibernate”),“hibernate插件与gorm hbase插件冲突”
//读取数据源配置,根据需要设置默认值
def dataSource=application.config.dataSource
//TODO为此编写测试
debug(“为域类$domainClass添加表”)
tableManager.createDomainTable(domainClass,createIndexedTables)
}
调试(“找到的所有存储列表:”)
tableManager.getTableNames()。每个{tn->
LOG.debug(“-$tn”)
}
}else if(dbCreate?.toUpperCase()?.equals(“更新”)){
def createIndexedTables=数据源?.indexed
def tableManager=HBaseLookupUtils.getBean(“hbase.table.manager”)
def existingTables=tableManager.getTableNames();
application.domainClasses.each{domainClass->
LOG.debug(“域类$domainClass”)
def tableDesc=新的HTableDescriptor(HBaseNameUtils.getDomainTableName(domainClass))
如果(!existingTables.contains(tableDesc.getNameAsString())){
tableManager.createDomainTable(domainClass,createIndexedTables)
debug(“为域类$domainClass添加表”)
}
}
}
application.domainClasses.each{domainClass->
debug(“将dbms相关方法添加到域类$domainClass”)
def domainClassManager=新的HBaseDomainClassManager()
domainClassManager.createQueryMethods(domainClass)
domainClassManager.createPersistenceMethods(domainClass)
domainClassManager.addLazyLoadingSupport(domainClass)
domainClassManager.addDynamicFinders(domainClass)
}
}