Module: DataMapper::Migrations::MysqlAdapter::SQL

Included in:
DataMapper::Migrations::MysqlAdapter
Defined in:
lib/dm-migrations/adapters/dm-mysql-adapter.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#storage_engineObject

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.



41
42
43
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 41

def storage_engine
  @storage_engine
end

Instance Method Details

#character_setObject

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.



102
103
104
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 102

def character_set
  @character_set ||= show_variable('character_set_connection') || DEFAULT_CHARACTER_SET
end

#collationObject

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.



107
108
109
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 107

def collation
  @collation ||= show_variable('collation_connection') || DEFAULT_COLLATION
end

#create_table_statement(connection, model, properties) ⇒ Object

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.



60
61
62
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 60

def create_table_statement(connection, model, properties)
  "#{super} ENGINE = #{storage_engine} CHARACTER SET #{character_set} COLLATE #{collation}"
end

#property_schema_hash(property) ⇒ Object

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.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 65

def property_schema_hash(property)
  schema = super

  if property.kind_of?(Property::Text)
    schema[:primitive] = text_column_statement(property.length)
    schema.delete(:default)
  end

  if property.kind_of?(Property::Integer)
    min = property.min
    max = property.max

    schema[:primitive] = integer_column_statement(min..max) if min && max
  end

  schema
end

#property_schema_statement(connection, schema) ⇒ Object

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.



84
85
86
87
88
89
90
91
92
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 84

def property_schema_statement(connection, schema)
  statement = super

  if supports_serial? && schema[:serial]
    statement << ' AUTO_INCREMENT'
  end

  statement
end

#schema_nameObject

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.



54
55
56
57
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 54

def schema_name
  # TODO: is there a cleaner way to find out the current DB we are connected to?
  normalized_uri.path.split('/').last
end

#show_variable(name) ⇒ Object

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.



112
113
114
115
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 112

def show_variable(name)
  result = select('SHOW VARIABLES LIKE ?', name).first
  result ? result.value.freeze : nil
end

#supports_drop_table_if_exists?Boolean

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:

  • (Boolean)


49
50
51
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 49

def supports_drop_table_if_exists?
  true
end

#supports_serial?Boolean

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:

  • (Boolean)


44
45
46
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 44

def supports_serial?
  true
end