2011-09-02 31 views
0

我使用grails-1.3.2和gorm-hbase-0.2.4插件。hbase - 如何更改表格結構而不使用drop表格

有時我需要更改表結構(添加新的表或列)。 我已經創建汽車表:

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 

後我運行create-應用滴,開始工作好.. 但我不能在每次更改後刪除所有數據, 我想插件必須做所有更新

所以,我期待某種方式後changind表結構繼續下降不表運行應用..

如果有人知道的解決方案,請幫助。

回答

1

Grails不會自動更新您的表格,如果它自動刪除生產中的某一列,該怎麼辦?也許這不是你想要的。

有一個數據庫遷移插件來做到這一點,這是一個很好的解釋它的link。請注意,您需要使用grails prod而不是直接在鏈接中使用鏈接,否則它將僅以開發模式運行。鏈接不顯示其命令。

官方鏈接是here和春天的來源博客關於這是here

0

數據庫遷移插件將不起作用,因爲它只適用於休眠。 您需要在插件源中進行一些更改。 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) 
    } 
}