Ticket #3735: add_primary_key.diff
| File add_primary_key.diff, 1.0 kB (added by nzkoz, 3 years ago) |
|---|
-
lib/active_record/connection_adapters/abstract/schema_statements.rb
old new 195 195 196 196 execute "CREATE #{index_type} INDEX #{index_name} ON #{table_name} (#{Array(column_name).join(", ")})" 197 197 end 198 199 # Adds a primary key to a table. The column name defaults to 'id'. 200 # Only supports integer primary keys, use +execute+ for legacy schema 201 # support 202 # ===== Example 203 # add_primary_key(:projects_developers) 204 # add_primary_key(:accounts, :acctno) 205 def add_primary_key(table_name, column_name='id') 206 execute "ALTER TABLE #{table_name} ADD #{column_name} #{native_database_types[:primary_key]}" 207 end 208 198 209 199 210 # Remove the given index from the table. 200 211 #