rails學(xué)習(xí)筆記: rake db 相關(guān)命令

命令行

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

數(shù)據(jù)類型

引用

# :string, :text, :integer, :float,:decimal, :datetime, :timestamp, :time, :date,

# :binary, :boolean

與db有關(guān)的rake任務(wù)

db:charset 檢索當(dāng)前環(huán)境下數(shù)據(jù)庫的字符設(shè)置

db:collation 檢索當(dāng)前環(huán)境下數(shù)據(jù)庫的校對

db:create 用config\database.yml中的定義創(chuàng)建當(dāng)前 RAILS_ENV 項目環(huán)境下的數(shù)據(jù)庫

db:create:all 用config\database.yml中的定義創(chuàng)建所有數(shù)據(jù)庫

db:drop 刪除當(dāng)前 RAILS_ENV項目環(huán)境中的數(shù)據(jù)庫

db:drop:all 刪除所有在 config\database.yml中定義的數(shù)據(jù)庫

db:reset 從db\schema.rb中為當(dāng)前環(huán)境重建數(shù)據(jù)庫(先刪后建).

db:rollback 回滾(清華出版社一本SQLSERVER書的名詞[很奇怪為什么不直接用滾回])數(shù)據(jù)庫到前一個版本. 指定回滾到哪一步要用 STEP=n 參數(shù)

db:version 檢索當(dāng)前模式下的版本

備份數(shù)據(jù)庫

rake db:backup:create 根據(jù)database.yml的信息備份數(shù)據(jù)庫

rake db:backup:destroy 默認(rèn)刪除一天前的備份數(shù)據(jù)

rake db:backup:rebuild 默認(rèn)恢復(fù)最新的備份數(shù)據(jù)

注意:這里設(shè)置的備份目錄是db的backup目錄揖膜,可以修改

添加索引

引用

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

add_index :acls, :action_id

drop all tables 刪除全部表

rake db:migrate VERSION=0

指定恢復(fù)/刪除:

rake db:migrate:down/up VERSION = version_of_migrati

定義數(shù)字精確度

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末誓沸,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子壹粟,更是在濱河造成了極大的恐慌拜隧,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,602評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件趁仙,死亡現(xiàn)場離奇詭異洪添,居然都是意外死亡,警方通過查閱死者的電腦和手機雀费,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,442評論 2 382
  • 文/潘曉璐 我一進店門干奢,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人盏袄,你說我怎么就攤上這事忿峻。” “怎么了辕羽?”我有些...
    開封第一講書人閱讀 152,878評論 0 344
  • 文/不壞的土叔 我叫張陵逛尚,是天一觀的道長。 經(jīng)常有香客問我刁愿,道長绰寞,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,306評論 1 279
  • 正文 為了忘掉前任,我火速辦了婚禮滤钱,結(jié)果婚禮上蕾管,老公的妹妹穿的比我還像新娘。我一直安慰自己菩暗,他們只是感情好掰曾,可當(dāng)我...
    茶點故事閱讀 64,330評論 5 373
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著停团,像睡著了一般旷坦。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上佑稠,一...
    開封第一講書人閱讀 49,071評論 1 285
  • 那天秒梅,我揣著相機與錄音,去河邊找鬼舌胶。 笑死捆蜀,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的幔嫂。 我是一名探鬼主播辆它,決...
    沈念sama閱讀 38,382評論 3 400
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼履恩!你這毒婦竟也來了锰茉?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,006評論 0 259
  • 序言:老撾萬榮一對情侶失蹤切心,失蹤者是張志新(化名)和其女友劉穎飒筑,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體绽昏,經(jīng)...
    沈念sama閱讀 43,512評論 1 300
  • 正文 獨居荒郊野嶺守林人離奇死亡协屡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 35,965評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了全谤。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片肤晓。...
    茶點故事閱讀 38,094評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖啼县,靈堂內(nèi)的尸體忽然破棺而出材原,到底是詐尸還是另有隱情,我是刑警寧澤季眷,帶...
    沈念sama閱讀 33,732評論 4 323
  • 正文 年R本政府宣布余蟹,位于F島的核電站,受9級特大地震影響子刮,放射性物質(zhì)發(fā)生泄漏威酒。R本人自食惡果不足惜窑睁,卻給世界環(huán)境...
    茶點故事閱讀 39,283評論 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望葵孤。 院中可真熱鬧担钮,春花似錦、人聲如沸尤仍。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,286評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽宰啦。三九已至苏遥,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間赡模,已是汗流浹背田炭。 一陣腳步聲響...
    開封第一講書人閱讀 31,512評論 1 262
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留漓柑,地道東北人教硫。 一個月前我還...
    沈念sama閱讀 45,536評論 2 354
  • 正文 我出身青樓,卻偏偏與公主長得像辆布,于是被迫代替她去往敵國和親瞬矩。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 42,828評論 2 345

推薦閱讀更多精彩內(nèi)容