What is the right approach to deal with Rails db/schema.rb file in GIT?

后端 未结 4 1464
南旧
南旧 2020-12-03 04:10

Should we include schema.rb while commiting to GIT? or should we ignore it? what is the right approach?

相关标签:
4条回答
  • 2020-12-03 04:50

    Well, it's not included on .gitignore by default. So, I think that you would not have a problem including it(I do in my projects, without any problem).

    0 讨论(0)
  • 2020-12-03 05:06

    Yes. The schema file is used to configure your database when using rake db:reset and other commands. Migrations should only be used when changing the database schema and will always result in a new schema file.

    0 讨论(0)
  • 2020-12-03 05:10

    I don't commit this file to Git, because it create when I launch rake db:migrate.

    If I will commit this file to Git, I cannot pull new changes from server after each db:migrate.

    0 讨论(0)
  • 2020-12-03 05:11

    Well the standard schema.rb file for Rails 2 has this at the end of the comment block at the top of the file:

    # It's strongly recommended to check this file into your version control system.
    

    The Rails 3 schema.rb that I have kicking around says the same thing. I think the comment says it all.


    Update in response to comments: Yes, mistakes can be made and you can get conflicting changes and bugs mangling your schema.rb but that's why you want it under revision control, revision control allows you to keep track of everything and backup when needed. There is only one thing in your entire source tree that specifies your database schema and that is schema.rb. Your database schema absolutely is a critical artifact and anything that important needs to be tracked in revision control.

    Any update/merge problems with schema.rb should be sorted out just by sorting out your conflicting migrations so schema.rb will get fixed as a side effect of fixing the real problem.

    Yes, schema.rb is a generated file but it is only generated in the sense that your text editor generates your pancake.rb model file or an unedited scaffold file is generated.

    Yes, you could rebuild your schema.rb file by building a new database and then running all of your migrations. But, you should clear out your old migrations now and then to avoid having to check hundreds of migration files every time you rake db:migrate so "rebuild and run all the migrations" often isn't an option in a highly active project.

    0 讨论(0)
提交回复
热议问题