Tambourine作業メモ

主にスキル習得のためにやった作業のメモ。他人には基本的に無用のものです。

あらら、話が前後した

というか、新しいテーブル構造についての記事が消えた。あら?

まず、テーブルの変更について、構造はこんな感じにする。

migrateを作る。まず、usersテーブル。これは簡単だ。

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.column :name, :string
    end
  end

  def self.down
    drop_table :users
  end
end

次に、possessionsテーブルとbooksテーブルの変更

class CreatePossessions < ActiveRecord::Migration
  def self.up
    create_table :possessions do |t|
      t.column :user_id,  :integer
      t.column :status,   :integer
      t.column :blog_url, :string
      t.column :isbn13,   :string
    end
    remove_column :books, :status
    remove_column :books, :blog_url
  end

  def self.down
    drop_table :possessions
    add_column :books, :status, :integer
    add_column :books, :blog_url, :string
  end
end

ところが、こっちはエラー。remove_columnは"alter table"を作るけど、DB2はalter tableで行の削除が出来ないみたい。なので、そこはコメントアウトして、コントロールセンターから実施する。