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.
rake db:migrate:reset                                           # Resets your database using your migrations for the current environment
rake db:migrate:up                                              # Runs the "up" for a given migration VERSION.
rake db:reset                                                       # Drops and recreates the database from db/schema.rb for the current environment.
rake db:rollback                                                   # Rolls the schema back to the previous version.
rake db:schema:dump                                      # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load                                     # Load a schema.rb file into the database
rake db:sessions:clear                                  # Clear the sessions table
rake db:sessions:create                               # Creates a sessions migration for use with CGI::Session::ActiveRecordStore
rake db:structure:dump                              # Dump the database structure to a SQL file
rake db:test:clone                                          # Recreate the test database from the current environment's database schema
rake db:test:clone_structure                         # Recreate the test databases from the development structure
rake db:test:load                                             # Recreate the test database from the current schema.rb
rake db:test:prepare                                     # Check for pending migrations and load the test schema
rake db:test:purge                                       # Empty the test database
rake db:version                                 # Retrieves the current schema version number
rake doc:app                        # Build the app HTML Files
rake doc:clobber_app                         # Remove rdoc products
rake doc:clobber_plugins                        # Remove plugin documentation
rake doc:clobber_rails                             # Remove rdoc products
rake doc:guides                                      # Generate Rails guides
rake doc:plugins                                    # Generate documentation for all installed plugins
rake doc:rails                                         # Build the rails HTML Files
rake doc:reapp                                       # Force a rebuild of the RDOC files
rake doc:rerails                                     # Force a rebuild of the RDOC files
rake gems                                               # List the gems that this rails application depends on
rake gems:build                                 # Build any native extensions for unpacked gems
rake gems:install                                         # Installs all required gems for this application.
rake gems:refresh_specs                                 # Regenerate gem specifications in correct format.
rake gems:unpack                                           # Unpacks the specified gem into vendor/gems.
rake gems:unpack:dependencies                                # Unpacks the specified gems and its dependencies into vendor/gems
rake log:clear                                                        # Truncates all *.log files in log/ to zero bytes
rake notes                                   # Enumerate all annotations
rake notes:custom                                     # Enumerate a custom annotation, specify with ANNOTATION=WTFHAX
rake notes:fixme                                       # Enumerate all FIXME annotations
rake notes:optimize                                       # Enumerate all OPTIMIZE annotations
rake notes:todo                                                  # Enumerate all TODO annotations
rake rails:freeze:edge                                         # Lock to latest Edge Rails, for a specific release use RELEASE=1.2.0
rake rails:freeze:gems                                       # Lock this application to the current gems (by unpacking them into vendor/rails)
rake rails:unfreeze                                  # Unlock this application from freeze of gems or edge and return to a fluid use of system gems
rake rails:update                                          # Update both configs, scripts and public/javascripts from Rails
rake rails:update:configs                                    # Update config/boot.rb from your current rails install
rake rails:update:javascripts                                   # Update your javascripts from your current rails install
rake rails:update:scripts                                    # Add new scripts to the application script/ directory
rake routes                                                      # Print out all defined routes in match order, with names.
rake secret                                               # Generate a crytographically secure secret key.
rake stats                                   # Report code statistics (KLOCs, etc) from the application
rake test                                               # Run all unit, functional and integration tests
rake test:benchmark                                # Run tests for benchmarkdb:test:prepare / Benchmark the performance tests
rake test:functionals                                    # Run tests for functionalsdb:test:prepare / Run the functional tests in test/functional
rake test:integration                                    # Run tests for integrationdb:test:prepare / Run the integration tests in test/integration
rake test:plugins                                             # Run tests for pluginsenvironment / Run the plugin tests in vendor/plugins/*/**/test (or specify with PLUGIN=name)
rake test:profile                                              # Run tests for profiledb:test:prepare / Profile the performance tests
rake test:recent                                        # Run tests for recentdb:test:prepare / Test recent changes
rake test:uncommitted                                    # Run tests for uncommitteddb:test:prepare / Test changes since last checkin (only Subversion and Git)
rake test:units                                      # Run tests for unitsdb:test:prepare / Run the unit tests in test/unit
rake time:zones:all                                   # Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset.
rake time:zones:local                                    # Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time
rake time:zones:us                                    # Displays names of US time zones recognized by the Rails TimeZone class, grouped by offset.
rake tmp:cache:clear                                  # Clears all files and directories in tmp/cache
rake tmp:clear                                               # Clear session, cache, and socket files from tmp/
rake tmp:create                                               # Creates tmp directories for sessions, cache, and sockets
rake tmp:pids:clear                                                # Clears all files in tmp/pids
rake tmp:sessions:clear                                          # Clears all files in tmp/sessions
rake tmp:sockets:clear                                             # Clears all files in tmp/sockets

时间: 2024-09-19 10:12:22

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

Ajax学习笔记整理_AJAX相关

Ajax: Asynchronous JavaScript and Xml , 异步js脚本和xml , 常用来实现页面局部的异步刷新, 对提高用户体验有很大帮助. Xml在多语言时较有优势, 但Ajax技术实际上较多采用Json对象而不是Xml来处理数据. Ajax历史....了解性知识 Ajax归属于Web前端开发技术, 与javascript有着异常紧密的联系. Ajax就是一种实现异步通信无刷新的技术, 而这种技术可以有很多种实现方式. 浏览器的鼻祖网景(NetScape)公司最早发明了

Rails学习笔记之Rails 基础教程

resource ,资源.一个资源就是一种相似对象的集合,比如文章,用户.你可以对资源执行创建,读取,更新,删除的动作,这些动作被称为 CRUD 操作. 一个博客,里面可能会有文章资源.创建一个文章资源,名字是 articles,先添加一个资源类型的路由.编辑 config/routes.rb,添加一行 resources :articles,像这样: Rails.application.routes.draw do   resources :articles   # ... end 执行: r

Ruby On Rails学习笔记(2)——Convention over Configuration(ROR应用程序的目录结构)

        XML形式的配置文件是Web开发中最常见的文件,如web.xml.applicationContext.xml.*.hbm.xml等等,这些文件在为应用程序提供强大的灵活性的同时也大大增加配置的复杂度.而Rails框架抛弃了这些配置文件,使用严格的约定,要求开发者将View.Controller.Model等各种类型文件放在自己专属的文件夹下,从而大大降低开发的复杂度,也即其Convention Over Configuration思想.       下图是一个典型的ROR应用程

Ruby On Rails学习笔记(1)——安装Instant Rails

       Instans Rails是一个ROR的一个一站式解决方案,其中包含了Ruby.Rails.Apache和MySQL,并且所有都已经配置完成,可以直接运行.下面是在Windows XP安装和启动Instant Rails的过程.       1.下载Instant Rails,下载地址为:http://rubyforge.org/frs/?group_id=904,当前最新的Release版本为1.7,即InstantRails-1.7-win.zip:       2.将Inst

ubuntu学习笔记之关机重启命令

常用命令 sudo shutdown –h now立刻关机 sudo shutdown –r now立刻重启 sudo shutdown –h nn分钟后关机 sudo shutdown –h 12:00到12:00是时候关机 sudo reboot立刻重启 注销 logout 问题:无法关机.重启 打开应用程序-附件-终端,然后在终端中输入 gksu gedit /etc/init.d/alsa-utils CTRL+F找到 mute_and_zero_levels "$TARGET_CARD

mysql学习笔记之常用sql命令

远程访问 mysql -h localhost -uroot -p 修改密码 mysqladmin -uroot -proot password admin 如果原密码为空 mysqladmin -uroot password admin 显示版本号.状态.进程信息等 mysqladmin version status proc 启动服务 net start mysql 关闭服务 mysqladmin -uroot -proot shutdown 查看版本和时间 select version()

Ruby On Rails学习笔记(4)——为first增加视图

         作为典型的MVC结构,绝对不会把显示的任务交给控制器,这需要有专业的视图来完成.在Rails中增加视图文件,同样是想当地的方便.下面就是为First应用程序的hello控制器增加index视图的详细步骤:        1.使用generate脚本生成视图:                   2.修改hello_controller.rb文件:                    3.在浏览器中查看自动生成的视图文件的显示效果:                       

Ruby On Rails学习笔记(3)——Rails程序由0到1

     正如Rails的理念一样,创建一个新的Rails应用程序的过程非常简单,下面就来看看如何从0到1建立一个全新的Rails应用程序.     1.启动InstantRails,打开其Rails应用程序管理器(Rails Application Manager):         2.创建一个名称为first的新的应用程序:              3.使用first应用程序中的脚本文件创建一个名称为hello的控制器:                   4.启动针对first应用程序

DWR util.js 学习笔记 整理_AJAX相关

util.js包含一些有用的函数function,用于在客户端页面调用,它可以和dwr分开,独立营用于你的系统中. 主要功能如下: 1.$() 获得页面参数值 2.addOptions and removeAllOptions 初始化下拉框 3.addRows and removeAllRows  填充表格 4.getText  取得text属性值 5.getValue 取得form表单值 6.getValues 取得form多个值 7.onReturn   8.selectRange 9.se