Method: Cequel::Schema::Keyspace#sync_table
- Defined in:
- lib/cequel/schema/keyspace.rb
#sync_table(name) { ... } ⇒ void Also known as: synchronize_table
This method returns an undefined value.
Create or update a table to match a given schema structure. The desired schema structure is defined by the directives given in the block; this is then compared to the existing table in the database (if it is defined at all), and then the table is created or altered accordingly.
225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/cequel/schema/keyspace.rb', line 225 def sync_table(name, &block) new_table_desc = TableDescDsl.new(name).eval(&block) patch = if has_table?(name) existing_table_desc = read_table(name) TableDiffer.new(existing_table_desc, new_table_desc).call else TableWriter.new(new_table_desc) # close enough to a patch end patch.statements.each{|stmt| keyspace.execute(stmt) } end |