Open KenjiOhtsuka opened 6 years ago
http://guides.rubyonrails.org/v3.2.9/migrations.html
add_column
add_index
change_column
change_table
create_table
drop_table
remove_column
remove_index
rename_column
already implemented
createTable
addColumn
: Must be tested
https://github.com/rails/rails/blob/f47b4236e089b07cb683ee9b7ff8b06111a0ec10/activerecord/lib/active_record/railties/databases.rake https://github.com/cakephp/phinx/blob/master/src/Phinx/Db/Adapter/PostgresAdapter.php https://gist.github.com/amejiarosario/2950888
Available transformations
Creation
create_join_table(table_1, table_2, options)
ActiveRecord::ConnectionAdapters::SchemaStatements#create_join_table
for details.create_table(name, options)
DEFAULT CHARSET=UTF-8
” that are appended to the create table definition.add_column(table_name, column_name, type, options)
:string
,:text
,:integer
,:float
,:decimal
,:datetime
,:timestamp
,:time
,:date
,:binary
,:boolean
.{ default: 11 }
. Other options include:limit
and:null
(e.g.{ limit: 50, null: false }
) – seeActiveRecord::ConnectionAdapters::TableDefinition#column
for details.add_foreign_key(from_table, to_table, options)
add_index(table_name, column_names, options)
:name
,:unique
(e.g.{ name: 'users_name_index', unique: true }
) and:order
(e.g.{ order: { name: :desc } }
).add_reference(:table_name, :reference_name)
ActiveRecord::ConnectionAdapters::SchemaStatements#add_reference
for details.add_timestamps(table_name, options)
Modification
change_column(table_name, column_name, type, options)
add_column
.change_column_default(table_name, column_name, default_or_changes)
:from
and:to
as default_or_changes will make this change reversible in the migration.change_column_null(table_name, column_name, null, default = nil)
NULL
.ActiveRecord::ConnectionAdapters::SchemaStatements#change_column_null
for details.change_table(name, options)
rename_column(table_name, column_name, new_column_name)
rename_index(table_name, old_name, new_name)
rename_table(old_name, new_name)
Deletion
drop_table(name)
drop_join_table(table_1, table_2, options)
remove_column(table_name, column_name, type, options)
remove_columns(table_name, *column_names)
: Removes the given columns from the table definition.remove_foreign_key(from_table, options_or_to_table)
remove_index(table_name, column: column_names)
remove_index(table_name, name: index_name)
remove_reference(table_name, ref_name, options)
remove_timestamps(table_name, options)