]> git.openstreetmap.org Git - rails.git/blob - lib/migrate.rb
Move common support code from the base migration to a library file where
[rails.git] / lib / migrate.rb
1 module ActiveRecord
2   module ConnectionAdapters
3     module SchemaStatements
4       def add_primary_key(table_name, column_name, options = {})
5         index_name = options[:name]
6         column_names = Array(column_name)
7         quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ")
8         execute "ALTER TABLE #{table_name} ADD PRIMARY KEY #{quote_column_name(index_name)} (#{quoted_column_names})"
9       end
10
11       alias_method :old_add_column_options!, :add_column_options!
12
13       def add_column_options!(sql, options)
14         old_add_column_options!(sql, options)
15         sql << " #{options[:options]}"
16       end
17
18       alias_method :old_options_include_default?, :options_include_default?
19
20       def options_include_default?(options)
21         old_options_include_default?(options) && !(options[:options] =~ /AUTO_INCREMENT/i)
22       end
23     end
24
25     class MysqlAdapter
26       alias_method :old_native_database_types, :native_database_types
27
28       def native_database_types
29         types = old_native_database_types
30         types[:bigint] = { :name => "bigint", :limit => 20 }
31         types
32       end
33     end
34   end
35 end
36
37 myisam_table = { :id => false, :force => true, :options => "ENGINE=MyIsam" }
38 innodb_table = { :id => false, :force => true, :options => "ENGINE=InnoDB" }