1

So I have an existing postgres database which gets populated by a python script. Now I am making a rails api which serves that data to a client. To my amusement all that I had to do is to create model classes and simply define relationships. No migration files, no schema, it just works. So a couple of questions.

  • Am I right in saying that schema.rb is only needed for creating the database? If I am not running any migrations in my rails app I don't need any schema or migration files at all?
  • I used to think that rails infers the names of model methods with the help of schema.rb . But it seems the only glue that ties ORM layer and the database is naming conventions? Are there any pitfalls I might be overlooking in doing things this way?

1 Answer 1

2

schema.rb is indeed not required by ActiveRecord.

It is used for:

  • having a quick overview of the state of the database
  • creating thedatabase tables when using db:schema:load task
  • in gems like Apartment, (I think) it is used to create tenant specific schemas

TL:DR; - you don't really need schema.rb file but it's always good to have it as an authoritative source of db information.

More info here: http://edgeguides.rubyonrails.org/active_record_migrations.html#schema-dumping-and-you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.