Module: SQL::Mysql
- Defined in:
- lib/dm-migrations/sql/mysql.rb
Defined Under Namespace
Instance Method Summary collapse
- #change_column_type_statement(name, column) ⇒ Object
- #property_schema_statement(connection, schema) ⇒ Object
- #recreate_database ⇒ Object
- #rename_column_type_statement(table_name, old_col, new_col) ⇒ Object
- #supports_schema_transactions? ⇒ Boolean
- #supports_serial? ⇒ Boolean
- #table(table_name) ⇒ Object
- #table_options(opts) ⇒ Object
Instance Method Details
#change_column_type_statement(name, column) ⇒ Object
39 40 41 |
# File 'lib/dm-migrations/sql/mysql.rb', line 39 def change_column_type_statement(name, column) "ALTER TABLE #{quote_name(name)} MODIFY COLUMN #{column.to_sql}" end |
#property_schema_statement(connection, schema) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/dm-migrations/sql/mysql.rb', line 31 def property_schema_statement(connection, schema) if supports_serial? && schema[:serial] "#{schema[:quote_column_name]} SERIAL PRIMARY KEY" else super end end |
#recreate_database ⇒ Object
13 14 15 16 17 |
# File 'lib/dm-migrations/sql/mysql.rb', line 13 def recreate_database execute "DROP DATABASE #{schema_name}" execute "CREATE DATABASE #{schema_name}" execute "USE #{schema_name}" end |
#rename_column_type_statement(table_name, old_col, new_col) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dm-migrations/sql/mysql.rb', line 43 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 = { 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, ) end column_definition = column.split(' ', 2).last "ALTER TABLE #{table} CHANGE #{quote_name(old_col)} #{quote_name(new_col)} #{column_definition}" end |
#supports_schema_transactions? ⇒ Boolean
5 6 7 |
# File 'lib/dm-migrations/sql/mysql.rb', line 5 def supports_schema_transactions? false end |
#supports_serial? ⇒ Boolean
19 20 21 |
# File 'lib/dm-migrations/sql/mysql.rb', line 19 def supports_serial? true end |
#table(table_name) ⇒ Object
9 10 11 |
# File 'lib/dm-migrations/sql/mysql.rb', line 9 def table(table_name) SQL::Mysql::Table.new(self, table_name) end |
#table_options(opts) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/dm-migrations/sql/mysql.rb', line 23 def (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 |