Skip to content

Instantly share code, notes, and snippets.

@metalefty
Last active August 29, 2015 13:56
Show Gist options
  • Save metalefty/9223871 to your computer and use it in GitHub Desktop.
Save metalefty/9223871 to your computer and use it in GitHub Desktop.
# SQLiteを使っていてカラム削除の migration を作るとこんな感じ?
class RemoveCFromT1 < ActiveRecord::Migration
def up
execute "
CREATE TEMPORARY TABLE t1_backup(a,b);
INSERT INTO t1_backup SELECT a,b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(a,b);
INSERT INTO t1 SELECT a,b FROM t1_backup;
DROP TABLE t1_backup;"
end
def down
add_column :t1, :c, :integer
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment