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

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

Overview

:nodoc:

Instance Method Summary collapse

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.



86
87
88
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 86

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.



91
92
93
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 91

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.



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

def create_table_statement(connection, model, properties)
  "#{super} ENGINE = #{DEFAULT_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.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 56

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.



75
76
77
78
79
80
81
82
83
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 75

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.



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

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.



96
97
98
99
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 96

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)


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

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)


35
36
37
# File 'lib/dm-migrations/adapters/dm-mysql-adapter.rb', line 35

def supports_serial?
  true
end