日期:2014-05-16  浏览次数:20427 次

rails学习笔记: rake db 相关命令
rails学习笔记: rake db

命令行
rake db:*****
script/generate model task name:string priority:integer  
script/generate migration add_description_to_task description:string  
script/generate migration remove_description_from_task description:string

数据类型
引用
# :string, :text, :integer, :float,:decimal, :datetime, :timestamp, :time, :date,
# :binary, :boolean

与db有关的rake任务

db:charset 检索当前环境下数据库的字符设置  
db:collation 检索当前环境下数据库的校对  
db:create 用config\database.yml中的定义创建当前 RAILS_ENV 项目环境下的数据库  
db:create:all 用config\database.yml中的定义创建所有数据库  
db:drop 删除当前 RAILS_ENV项目环境中的数据库  
db:drop:all 删除所有在 config\database.yml中定义的数据库  
db:reset 从db\schema.rb中为当前环境重建数据库(先删后建).  
db:rollback 回滚(清华出版社一本SQLSERVER书的名词[很奇怪为什么不直接用滚回])数据库到前一个版本. 指定回滚到哪一步要用 STEP=n 参数  
db:version 检索当前模式下的版本  

备份数据库
rake db:backup:create 根据database.yml的信息备份数据库
rake db:backup:destroy 默认删除一天前的备份数据
rake db:backup:rebuild 默认恢复最新的备份数据

注意:这里设置的备份目录是db的backup目录,可以修改

添加索引
引用

add_index :acls, ["action_id","group_id"],:unique=>true
add_index :acls, :action_id

drop all tables 删除全部表
rake db:migrate VERSION=0 

指定恢复/删除:
rake db:migrate:down/up VERSION = version_of_migrati

定义数字精确度
t.integer :total_price, :precision=>8,:scale=>2,:default=>0


========================================================================================================================================================
rake db:abort_if_pending_migrations  # Raises an error if there are pending migrations
rake db:charset                      # Retrieves the charset for the current environment's database
rake db:collation                    # Retrieves the collation for the current environment's database
rake db:create                       # Create the database defined in config/database.yml for the current RAILS_ENV
rake db:create:all                   # Create all the local databases defined in config/database.yml
rake db:drop                         # Drops the database for the current RAILS_ENV
rake db:drop:all                     # Drops all the local databases defined in config/database.yml
rake db:fixtures:identify            # Search for a fixture given a LABEL or ID.
rake db:fixtures:load                # Load fixtures into the current environment's database.
rake db:migrate                      # Migrate the database through scripts in db/migrate.
rake db:migrate:down                 # Runs the "down" for a given migration VERSION.
rake db:migrate:redo                 # Rollbacks the database one migration and re migrate up.
rak