aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/mysql
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2015-10-13 01:21:49 +0900
committerRyuta Kamizono <kamipo@gmail.com>2015-10-13 01:32:05 +0900
commit1e797e5ba862b85169c78e0da544218e8eba3045 (patch)
tree158b659de3d295bd5550a1d98d10e3c67ccb021f /activerecord/lib/active_record/connection_adapters/mysql
parent9f4cefd28ff2d126a5b314e80cf609709226d5ad (diff)
downloadrails-1e797e5ba862b85169c78e0da544218e8eba3045.tar.gz
rails-1e797e5ba862b85169c78e0da544218e8eba3045.tar.bz2
rails-1e797e5ba862b85169c78e0da544218e8eba3045.zip
Move the methods for schema dumping into `{mysql,postgresql}/schema_dumper.rb`
Current master branch includes many schema dumping improvements. It extract these features to the appropriate files.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/mysql')
-rw-r--r--activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
new file mode 100644
index 0000000000..6448b8b5e2
--- /dev/null
+++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_dumper.rb
@@ -0,0 +1,48 @@
+module ActiveRecord
+ module ConnectionAdapters
+ module MySQL
+ module ColumnDumper
+ def column_spec_for_primary_key(column)
+ spec = {}
+ if column.auto_increment?
+ spec[:id] = ':bigint' if column.bigint?
+ spec[:unsigned] = 'true' if column.unsigned?
+ return if spec.empty?
+ else
+ spec[:id] = column.type.inspect
+ spec.merge!(prepare_column_options(column).delete_if { |key, _| [:name, :type, :null].include?(key) })
+ end
+ spec
+ end
+
+ def prepare_column_options(column)
+ spec = super
+ spec[:unsigned] = 'true' if column.unsigned?
+ spec
+ end
+
+ def migration_keys
+ super + [:unsigned]
+ end
+
+ private
+
+ def schema_limit(column)
+ super unless column.type == :boolean
+ end
+
+ def schema_precision(column)
+ super unless /time/ === column.sql_type && column.precision == 0
+ end
+
+ def schema_collation(column)
+ if column.collation && table_name = column.instance_variable_get(:@table_name)
+ @table_collation_cache ||= {}
+ @table_collation_cache[table_name] ||= select_one("SHOW TABLE STATUS LIKE '#{table_name}'")["Collation"]
+ column.collation.inspect if column.collation != @table_collation_cache[table_name]
+ end
+ end
+ end
+ end
+ end
+end