Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
8
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

Organization

Rails で schema_format を :sql にしたときに AUTO_INCREMENT を含まないようにする

lib/tasks/dump.rake

namespace :db do
  namespace :structure do
    task :dump do
      path = Rails.root.join('db', 'structure.sql')
      cont = File.open(path).read.gsub(/ AUTO_INCREMENT=\d*/, '')
      File.open(path, 'wb') {|f| f.puts cont }
    end
  end
end

正規表現で消してるだけです。

これで出来上がった structure.sql は rake db:reset とか rake db:schema:load とかで使われますが、特に大きな理由が無い限り rake db:migrate 使う方がいいとは思っています。
(migration を全て実行することと schema.rb や structure.sql をロードすることはイコールではないので)

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
8
Help us understand the problem. What are the problem?