ruby on rails - How can I write a down or reversible function in this migration? -
so, in-case migration causes errors i'd able revert back/rake db:rollback.
the code:
class changeuidtoprimarykey < activerecord::migration def change execute alter table "users" drop constraint "users_pkey". execute alter table "users" add primary key "uid" end end
what down/reversible code can add make rake db:rollback work in case?
you following i.e. keeping unique index on email
if need revert back.
class changeuidtoprimarykey < activerecord::migration def self.up execute "alter table users add constraint unique_users_email unique(email)" execute "alter table users drop constraint users_pkey" execute "alter table users add primary key (uid)" end def self.down execute "alter table users drop constraint users_pkey" execute "alter table users drop constraint unique_users_email" execute "alter table users add primary key (email)" end end
Comments
Post a Comment