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

简介: rails学习笔记: rake db 命令行 rake db:***** script/generate model task name:string priority:integer script/generate migration add_description_to_ta...
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
目录
相关文章
《深入理解高并发编程(第2版)》八大篇章,共433页,打包发布!!
大家好,我是冰河~~ 在 冰河技术 微信公众号中的【精通高并发系列】专题,更新了不少文章,有些读者反馈说,在公众号中刷历史文章不太方便,有时会忘记自己看到哪一篇了,当打开一篇文章时,似乎之前已经看过了,但就是不知道具体该看哪一篇了。相信很多小伙伴都会有这样的问题。那怎么办呢? 最好的解决方案就是我把这些文章整理成PDF电子书,免费分享给大家,这样,小伙伴们看起来就方便多了。
1380 0
《深入理解高并发编程(第2版)》八大篇章,共433页,打包发布!!
|
11月前
|
存储 关系型数据库 分布式数据库
[PolarDB实操课] 01.PolarDB分布式版架构介绍
《PolarDB实操课》之“PolarDB分布式版架构介绍”由阿里云架构师王江颖主讲。课程涵盖PolarDB-X的分布式架构、典型业务场景(如实时交易、海量数据存储等)、分布式焦点问题(如业务连续性、一致性保障等)及技术架构详解。PolarDB-X基于Share-Nothing架构,支持HTAP能力,具备高可用性和容错性,适用于多种分布式改造和迁移场景。课程链接:[https://developer.aliyun.com/live/253957](https://developer.aliyun.com/live/253957)。更多内容可访问阿里云培训中心。
263 0
[PolarDB实操课] 01.PolarDB分布式版架构介绍
|
SQL 缓存 Java
mybatis 一对多查询
mybatis 一对多查询
394 0
|
存储 数据可视化 API
重磅干货,免费三方网络验证[用户系统+CDK]全套API接口分享教程。
本套网络验证系统提供全面的API接口,支持用户注册、登录、数据查询与修改、留言板管理等功能,适用于不想自建用户系统的APP开发者。系统还包含CDK管理功能,如生成、使用、查询和删除CDK等。支持高自定义性,包括20个自定义字段,满足不同需求。详细接口参数及示例请参考官方文档。
449 7
|
传感器 物联网 网络虚拟化
物联网卡怎么取消区域限制
物联网卡(IoT SIM卡)通常用于连接物联网设备,如智能城市设备、工业传感器、车载设备等,以实现数据的远程传输和设备的远程管理。物联网卡通常会有区域限制,即只能在特定的地区或国家内使用。取消物联网卡的区域限制并不是一个直接的操作,因为这通常取决于服务提供商的政策和合同条款。不过,以下是一些可能的步骤和建议,可以尝试来解除或绕过这些限制:
|
存储 分布式计算 Hadoop
Hadoop性能问题
【7月更文挑战第12天】
278 11
|
前端开发 应用服务中间件 nginx
docker Compose 部署springboot+vue前端端分离项目
docker Compose 部署springboot+vue前端端分离项目
1394 1
|
缓存 运维 负载均衡
阿里云云效操作报错合集之在获取Maven私有库配置出错,该如何操作
本合集将整理呈现用户在使用过程中遇到的报错及其对应的解决办法,包括但不限于账户权限设置错误、项目配置不正确、代码提交冲突、构建任务执行失败、测试环境异常、需求流转阻塞等问题。阿里云云效是一站式企业级研发协同和DevOps平台,为企业提供从需求规划、开发、测试、发布到运维、运营的全流程端到端服务和工具支撑,致力于提升企业的研发效能和创新能力。
|
Linux
Linux下采集摄像头的图像再保存为JPG图片存放到本地(YUYV转JPG)
Linux下采集摄像头的图像再保存为JPG图片存放到本地(YUYV转JPG)
2310 2
Linux下采集摄像头的图像再保存为JPG图片存放到本地(YUYV转JPG)
|
前端开发 IDE Java
JDK 新特性学习笔记之模块系统
JDK 新特性学习笔记之模块系统