読者です 読者をやめる 読者になる 読者になる

migrationで直接SQL

rails
class CreateUploadeds < ActiveRecord::Migration
  def self.up
    create_table :uploadeds do |t|
      t.column :memo_id, :integer
      t.column :name, :string
      t.column :path, :string
    end
    remove_column :memos, :image1
    remove_column :memos, :image2
    remove_column :memos, :image3
    remove_column :memos, :image4
    add_index "uploadeds", ["memo_id"], :name => "memo_id"
  end

  def self.down
    drop_table :uploadeds
    execute 'alter table memos add image1 mediumblob'
    execute 'alter table memos add image2 mediumblob'
    execute 'alter table memos add image3 mediumblob'
    execute 'alter table memos add image4 mediumblob'
    remove_index "uploadeds", :name => "memo_id"
  end
end

本筋と関係ないけど、以下の記述だとエラーになった

    create_table :uploadeds {|t|
      t.column :memo_id, :integer
      t.column :name, :string
      t.column :path, :string
    }