@api semipublic
# File lib/dm-migrations/adapters/dm-do-adapter.rb, line 86 86: def create_model_storage(model) 87: name = self.name 88: properties = model.properties_with_subclasses(name) 89: 90: return false if storage_exists?(model.storage_name(name)) 91: return false if properties.empty? 92: 93: with_connection do |connection| 94: statements = [ create_table_statement(connection, model, properties) ] 95: statements.concat(create_index_statements(model)) 96: statements.concat(create_unique_index_statements(model)) 97: 98: statements.each do |statement| 99: command = connection.create_command(statement) 100: command.execute_non_query 101: end 102: end 103: 104: true 105: end
@api semipublic
# File lib/dm-migrations/adapters/dm-do-adapter.rb, line 108 108: def destroy_model_storage(model) 109: return true unless supports_drop_table_if_exists? || storage_exists?(model.storage_name(name)) 110: execute(drop_table_statement(model)) 111: true 112: end
Returns whether the field exists.
@param [String] storage_name
a String defining the name of a storage, for example a table name.
@param [String] field
a String defining the name of a field, for example a column name.
@return [Boolean]
true if the field exists.
@api semipublic
# File lib/dm-migrations/adapters/dm-do-adapter.rb, line 40 40: def field_exists?(storage_name, column_name) 41: statement = DataMapper::Ext::String.compress_lines( SELECT COUNT(*) FROM "information_schema"."columns" WHERE "table_schema" = ? AND "table_name" = ? AND "column_name" = ?) 42: 43: select(statement, schema_name, storage_name, column_name).first > 0 44: end
Returns whether the storage_name exists.
@param [String] storage_name
a String defining the name of a storage, for example a table name.
@return [Boolean]
true if the storage exists
@api semipublic
# File lib/dm-migrations/adapters/dm-do-adapter.rb, line 17 17: def storage_exists?(storage_name) 18: statement = DataMapper::Ext::String.compress_lines( SELECT COUNT(*) FROM "information_schema"."tables" WHERE "table_type" = 'BASE TABLE' AND "table_schema" = ? AND "table_name" = ?) 19: 20: select(statement, schema_name, storage_name).first > 0 21: end
@api semipublic
# File lib/dm-migrations/adapters/dm-do-adapter.rb, line 53 53: def upgrade_model_storage(model) 54: name = self.name 55: properties = model.properties_with_subclasses(name) 56: 57: if success = create_model_storage(model) 58: return properties 59: end 60: 61: table_name = model.storage_name(name) 62: 63: with_connection do |connection| 64: properties.map do |property| 65: schema_hash = property_schema_hash(property) 66: next if field_exists?(table_name, schema_hash[:name]) 67: 68: statement = alter_table_add_column_statement(connection, table_name, schema_hash) 69: command = connection.create_command(statement) 70: command.execute_non_query 71: 72: # For simple :index => true columns, add an appropriate index. 73: # Upgrading doesn't know how to deal with complex indexes yet. 74: if property.options[:index] === true 75: statement = create_index_statement(model, property.name, [property.field]) 76: command = connection.create_command(statement) 77: command.execute_non_query 78: end 79: 80: property 81: end.compact 82: end 83: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.