Module: SQL::Mysql

Defined in:
lib/dm-migrations/sql/mysql.rb

Defined Under Namespace

Classes: Column, Table

Instance Method Summary (collapse)

Instance Method Details

- (Object) change_column_type_statement(name, column)



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

def change_column_type_statement(name, column)
  "ALTER TABLE #{quote_name(name)} MODIFY COLUMN #{column.to_sql}"
end

- (Object) property_schema_statement(connection, schema)



32
33
34
35
36
37
38
# File 'lib/dm-migrations/sql/mysql.rb', line 32

def property_schema_statement(connection, schema)
  if supports_serial? && schema[:serial]
    statement = "#{schema[:quote_column_name]} SERIAL PRIMARY KEY"
  else
    super
  end
end

- (Object) recreate_database



14
15
16
17
18
# File 'lib/dm-migrations/sql/mysql.rb', line 14

def recreate_database
  execute "DROP DATABASE #{schema_name}"
  execute "CREATE DATABASE #{schema_name}"
  execute "USE #{schema_name}"
end

- (Object) rename_column_type_statement(table_name, old_col, new_col)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dm-migrations/sql/mysql.rb', line 44

def rename_column_type_statement(table_name, old_col, new_col)
  table       = quote_name(table_name)
  column_info = select("SHOW COLUMNS FROM #{table} LIKE ?", old_col).first

  column_options = {
    :name      => column_info.field,
    :primitive => column_info.type,
    :serial    => column_info.extra == 'auto_increment',
    :allow_nil => column_info.null == 'YES',
    :default   => column_info.default,
  }

  column = with_connection do |connection|
    property_schema_statement(connection, column_options)
  end

  column_definition = column.split(' ', 2).last

  "ALTER TABLE #{table} CHANGE #{quote_name(old_col)} #{quote_name(new_col)} #{column_definition}"
end

- (Boolean) supports_schema_transactions?

Returns:

  • (Boolean)


6
7
8
# File 'lib/dm-migrations/sql/mysql.rb', line 6

def supports_schema_transactions?
  false
end

- (Boolean) supports_serial?

Returns:

  • (Boolean)


20
21
22
# File 'lib/dm-migrations/sql/mysql.rb', line 20

def supports_serial?
  true
end

- (Object) table(table_name)



10
11
12
# File 'lib/dm-migrations/sql/mysql.rb', line 10

def table(table_name)
  SQL::Mysql::Table.new(self, table_name)
end

- (Object) table_options(opts)



24
25
26
27
28
29
30
# File 'lib/dm-migrations/sql/mysql.rb', line 24

def table_options(opts)
  opt_engine    = opts[:storage_engine] || storage_engine
  opt_char_set  = opts[:character_set] || character_set
  opt_collation = opts[:collation] || collation

  " ENGINE = #{opt_engine} CHARACTER SET #{opt_char_set} COLLATE #{opt_collation}"
end