New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db:schema:load vs rake db:migrate #184

Open
edorgeville opened this Issue May 27, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@edorgeville

edorgeville commented May 27, 2016

Use rake db:schema:load instead of rake db:migrate to initialize an empty database.
https://github.com/bbatsov/rails-style-guide#db-schema-load

Why use one over the other ? Only info I found was going against using db:schema:load as running it on a production server would simply wipe existing database data. (http://stackoverflow.com/a/5905958)

Is it only useful for projects with deleted old migrations ? Is it good practice to delete old migrations you know won't ever be needed again ?

Thanks !

@espadrine

This comment has been minimized.

espadrine commented Dec 22, 2017

@edorgeville Running it in production would indeed wipe the data, which indeed does what the quote implies:

to initialize an empty database.

If that is exactly what you want to do, which you sometimes wish to do locally to clean the slate, then db:schema:load will set up the database according to db/schema.rb instead of running all your migrations from db/migrate/, which may include migrations that represent needless work (eg, if a column changed name at some point and was later removed, you don't need to perform the name change, just the removal).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment