diff options
author | Yves Senn <yves.senn@gmail.com> | 2015-10-12 16:22:52 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2015-10-12 16:22:52 +0200 |
commit | 4f9ffd51055e16e50588934da04fb7a2438a871d (patch) | |
tree | 87cac7a431c80a320d0c39af61ee6ffffa5a25bc /activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb | |
parent | f39ab9f3436a498f08c14578f5ea67591150bf27 (diff) | |
parent | 11fc84c0137408c22222925f8e16a4e28a60c9c5 (diff) | |
download | rails-4f9ffd51055e16e50588934da04fb7a2438a871d.tar.gz rails-4f9ffd51055e16e50588934da04fb7a2438a871d.tar.bz2 rails-4f9ffd51055e16e50588934da04fb7a2438a871d.zip |
Merge pull request #21933 from kamipo/move_schema_definiton_classes_into_appropriate_file
Move schema definiton classes into the appropriate files
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb new file mode 100644 index 0000000000..1e2c859af9 --- /dev/null +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb @@ -0,0 +1,57 @@ +module ActiveRecord + module ConnectionAdapters + module MySQL + class SchemaCreation < AbstractAdapter::SchemaCreation + private + + def visit_DropForeignKey(name) + "DROP FOREIGN KEY #{name}" + end + + def visit_ColumnDefinition(o) + o.sql_type = type_to_sql(o.type, o.limit, o.precision, o.scale, o.unsigned) + super + end + + def visit_AddColumnDefinition(o) + add_column_position!(super, column_options(o.column)) + end + + def visit_ChangeColumnDefinition(o) + change_column_sql = "CHANGE #{quote_column_name(o.name)} #{accept(o.column)}" + add_column_position!(change_column_sql, column_options(o.column)) + end + + def column_options(o) + column_options = super + column_options[:charset] = o.charset + column_options + end + + def add_column_options!(sql, options) + if options[:charset] + sql << " CHARACTER SET #{options[:charset]}" + end + if options[:collation] + sql << " COLLATE #{options[:collation]}" + end + super + end + + def add_column_position!(sql, options) + if options[:first] + sql << " FIRST" + elsif options[:after] + sql << " AFTER #{quote_column_name(options[:after])}" + end + sql + end + + def index_in_create(table_name, column_name, options) + index_name, index_type, index_columns, _, _, index_using = @conn.add_index_options(table_name, column_name, options) + "#{index_type} INDEX #{quote_column_name(index_name)} #{index_using} (#{index_columns}) " + end + end + end + end +end |