12
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

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 をロードすることはイコールではないので)

12
8
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
12
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?