lib/swift/db.rb in swift-0.7.1 vs lib/swift/db.rb in swift-0.7.2
- old
+ new
@@ -34,17 +34,21 @@
def returning?
false
end
- def drop_store name
- exists_sql =<<-SQL
- select count(*) as exists from syscat.tables where tabschema = CURRENT_SCHEMA and tabname = '#{name.upcase}'
+ def migrate!
+ keys = scheme.header.keys
+ fields = scheme.header.map{|p| field_definition(p)}.join(', ')
+ fields += ", primary key (#{keys.join(', ')})" unless keys.empty?
+
+ sql = <<-SQL
+ select count(*) as exists from syscat.tables
+ where tabschema = CURRENT_SCEMA and tabname = '#{scheme.store.upcase}'
SQL
- execute(exists_sql.strip) do |r|
- execute("drop table #{name}") if r[:exists] > 0
- end
+ execute(sql) {|result| execute("drop table #{scheme.store}") if result[:exists] > 0 }
+ execute("create table #{scheme.store} (#{fields})")
end
def field_type attribute
case attribute
when Type::String then 'clob(2g)'