LoginSignup
25
20

More than 5 years have passed since last update.

ridgepoleの初期設定と使い方

Last updated at Posted at 2016-04-23

初めてridgepoleを使おうと思ったが初期設定が書いてあるサイトがなかなか見当たらなかったので作成.
おかしな点があればコメントか編集リクエストお願します.

ridgepoleとは

railsでは通常はmigrateファイルによってDBのスキーマを管理している.
が追加/削除/リネームが結構面倒くさい.
そこで毎回migrateする必要がなくなり、ファイルを書き直すだけで簡単にスキーマの管理ができるGemであるridgepoleを使おうということである.

DB作成

rake db:create

Gemfile

gem 'ridgepole'

してbundle install

ridgepole.ymlの作成

config/ridgepole.ymlを新規作成する
ファイル名、階層は自由(config配下であることは必須?)

config/ridgepole.yml
adapter: mysql2
encoding: utf8
database: ????????
username: ????????
password: ????????

Schemafileを作成

他の人はdbディレクトリの中に作ったりしてる.
自分はconfig直下に作った.

config/Schemafile

create_table "articles", force: true do |t|
  t.string   "title"
  t.text   "content"
  t.integer  "status"
  t.datetime "created_at"
  t.datetime "updated_at"
end

ridgepoleコマンド

ridgepole -c config/ridgepole.yml --apply -f config/Schemafile

ridgepole -c (dbの設定ファイルのpath) --apply -f (Schemafileのpath)

でSchemafileの内容を反映できる.

ridgepole導入後

今後はmigrateコマンドを一切使わないので
rails g modelやrails g scaffoldなどmigrateが必要なコマンドを実行する場合は最後に「--skip-migration」を付ける.(rails g controllerはmigrate不要だったはず)

rails g scaffold Article content:text --skip-migration
rails g model Article --skip-migration

余計なmigrateファイルがあるとエラーになるので間違えて生成した場合は rm -rfで削除する

デプロイしたら

bundle exec ridgepole -c config/ridgepole.yml -E production --apply -f config/Schemafile

bundle execつけないと

-bash: ridgepole: コマンドが見つかりません

ridgepole: command not found

になる

参考サイト

ridgepoleの初期設定と使い方

25
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
25
20