Class: Cequel::Schema::TableSynchronizer
- Inherits:
-
Object
- Object
- Cequel::Schema::TableSynchronizer
- Defined in:
- lib/cequel/schema/table_synchronizer.rb
Overview
Synchronize a table schema in the database with a desired table schema
Instance Attribute Summary collapse
-
#existing ⇒ Table
readonly
private
Table as it is currently defined.
-
#updated ⇒ Table
readonly
private
Table schema as it is desired.
Class Method Summary collapse
-
.apply(keyspace, existing, updated) ⇒ void
Takes an existing table schema read from the database, and a desired schema for that table.
Instance Method Summary collapse
-
#apply ⇒ void
private
Apply the changes needed to synchronize the schema in the database with the desired schema.
-
#each_clustering_column_pair {|old_clustering_column, new_clustering_column| ... } ⇒ void
private
Iterate over pairs of (old_clustering_column, new_clustering_column).
-
#each_data_column_pair {|old_column, new_column| ... } ⇒ void
private
Iterate over pairs of (old_column, new_column).
-
#each_key_pair {|old_key, new_key| ... } ⇒ void
private
Iterate over pairs of (old_key, new_key).
- #initialize(updater, existing, updated) ⇒ void constructor
Constructor Details
#initialize(updater, existing, updated) ⇒ void
46 47 48 |
# File 'lib/cequel/schema/table_synchronizer.rb', line 46 def initialize(updater, existing, updated) @updater, @existing, @updated = updater, existing, updated end |
Instance Attribute Details
#existing ⇒ Table (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns table as it is currently defined.
12 13 14 |
# File 'lib/cequel/schema/table_synchronizer.rb', line 12 def existing @existing end |
#updated ⇒ Table (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns table schema as it is desired.
15 16 17 |
# File 'lib/cequel/schema/table_synchronizer.rb', line 15 def updated @updated end |
Class Method Details
.apply(keyspace, existing, updated) ⇒ void
This method returns an undefined value.
Takes an existing table schema read from the database, and a desired schema for that table. Modifies the table schema in the database to match the desired schema, or creates the table as specified if it does not yet exist
28 29 30 31 32 33 34 35 36 |
# File 'lib/cequel/schema/table_synchronizer.rb', line 28 def self.apply(keyspace, existing, updated) if existing TableUpdater.apply(keyspace, existing.name) do |updater| new(updater, existing, updated).apply end else TableWriter.apply(keyspace, updated) end end |
Instance Method Details
#apply ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Apply the changes needed to synchronize the schema in the database with the desired schema
60 61 62 63 64 65 |
# File 'lib/cequel/schema/table_synchronizer.rb', line 60 def apply validate! update_keys update_columns update_properties end |
#each_clustering_column_pair {|old_clustering_column, new_clustering_column| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Iterate over pairs of (old_clustering_column, new_clustering_column)
112 113 114 |
# File 'lib/cequel/schema/table_synchronizer.rb', line 112 def each_clustering_column_pair(&block) existing.clustering_columns.zip(updated.clustering_columns, &block) end |
#each_data_column_pair {|old_column, new_column| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Iterate over pairs of (old_column, new_column)
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cequel/schema/table_synchronizer.rb', line 89 def each_data_column_pair(&block) if existing.compact_storage? && existing.clustering_columns.any? yield existing.data_columns.first, updated.data_columns.first else old_columns = existing.data_columns.index_by { |col| col.name } new_columns = updated.data_columns.index_by { |col| col.name } all_column_names = (old_columns.keys + new_columns.keys).tap(&:uniq!) all_column_names.each do |name| yield old_columns[name], new_columns[name] end end end |
#each_key_pair {|old_key, new_key| ... } ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Iterate over pairs of (old_key, new_key)
76 77 78 |
# File 'lib/cequel/schema/table_synchronizer.rb', line 76 def each_key_pair(&block) existing.key_columns.zip(updated.key_columns, &block) end |