rails migration

  长整形定义 

t.column :author_id, 'BIGINT UNSIGNED'
t
.integer :author_id, :limit => 8

 

class AccountTasks < ActiveRecord::Migration

  def self.up

    create_table :account_tasks do |t|

      t.string :account_name,:null=>false

      t.string :account_type,:default=>"C2C"

      t.string :initial_pwd, :default=>"111"

      t.integer :account_suffix, :default=>3

      t.integer :count,:default=>1

      t.integer :balance,:default=>10000

 

      t.string :task_status,:default=>"new"

      t.string :applicant, :null=>false

      t.string :applicant_email, :null=>false

      t.text :detail

 

      t.timestamps

    end

 

    add_index :account_tasks, :account_name, :unique => true

  end

 

  def self.down

    remove_index :account_tasks, :column => :account_name

    drop_table :account_tasks    

  end

end

 

 

 

class DailyAccounts < ActiveRecord::Migration

  def self.up

    create_table :daily_accounts, :force=>true do |t|

      t.references :account_task

 

      t.string :account_type, :default=>"C2C", :null=>false

      # account info

      t.string :tb_account, :null=>false

      t.string :tb_login_pwd, :default=>"111",:null=>false

      # use bits (from heigh bit to low bit): authentic|activated|duplicated

      t.text :tb_account_status

 

      # pay account info

      t.string :pay_account, :null=>false

      t.string :pay_login_pwd, :default=>"111",:null=>false

      t.string :pay_pay_pwd, :default=>"111",:null=>false

      t.integer :pay_balance, :default=>"10000",:null=>false

 

      # use bits (from heigh bit to low bit): authentic|balance|activated|config|duplicated

      t.text :pay_account_status

 

      # auto filled by tb_account_status, pay_account_status

      t.string :result

      t.text  :detail

 

      t.timestamps

    end

 

    add_index :day_accounts, :tb_account, :unique => true

  end

 

  def self.down

    remove_index :day_accounts, :column => :tb_account

    drop_table :day_accounts    

  end

end

 

 

  • ActiveRecord::Schema.define(:version => 5do  
  •   
  •   create_table "choices",:id => false, :force => true do |t|  
  •   
  •     t.column "name", :string,, :limit => 30, :default => 'idiolt'  
  •   
  •     t.column "content", :text, :limit => 100  
  •   
  •     t.column "question_id", :integer, :null => false  
  •   
  •   end  
  •   
  • ...  
  •   
  • :version以后用了migrate才会看见,现在应该是空的,先不管这个. 如你所见这个表定义非常直观.需要说明的几个选项.  
  •   
  • :force代表强制覆盖,默认false后面执行db:schema:load把表结构导回数据库的时候如果表已经存在由这个选项决定是否覆盖. :id参数默认为true,也就是按照rails约定每个表自动建立id字段作为主键.false的话意思是你自己在schema中建立主键. :limit和:default不用解释了吧. :null也没啥好解释的,false代表着SQL里的NOT NULL  
  •   
  • 你们已经看到db:schema:load了,恭喜,现在哪怕你不关心版本控制和分布式同步这些 "遥远的事". 你也可以从容在各种不同数据库直接移植表结构了.这可是DBA都头疼的事呢. 只要改一下database.yml的配置再执行rake db:schema:load就可以了.  
  •   <以上转自http://dogstar.javaeye.com/blog/54233>
  •  

     

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值