P
P
Promix172015-02-17 21:30:50
Ruby on Rails
Promix17, 2015-02-17 21:30:50

What is the high-level relationship between ActiveRecord and migrations in rails?

I'm doing a project where ActiveRecord is used and migrations without rails. Ideas taken from here:
habrahabr.ru/post/98751
blog.aizatto.com/2007/05/21/activerecord-without-rails
blog.aizatto.com/2007/05/27/activerecord-migration...
I wanted to generate files automatically , as in rails - did not find a solution and gave rise to the following crutch:
https://rubygems.org/gems/rails_tools.
But here's the thing - I don't understand the philosophy of ActiveRecord communication, migration, and the high-level entity of the model. Why is the description of the model lost after the rails g model command? Why do I have to manually add has_many operators to ActiveRecord::Base derivatives? Is there a way to describe the model in some DSL and then generate ActiveRecord::Base class derivatives and migrations automatically? Why was such a mechanism for generating entities through the console chosen, and not a config on the DSL? I can't even determine the structure of a particular ActiveRecord element without referring to the migration file.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
OnYourLips, 2015-02-17
@OnYourLips

If you do it the way you want, then subsequent changes will have to be duplicated (both migration and model change), and this is not convenient.
To see how inconvenient this is, take a look at Django.

P
Promix17, 2015-02-18
@Promix17

I don't really understand the next changes. If you do as I suggest, then when you change, you just need to change one main model description file to DSL and make automatic generation of migration and model files in one command. At the same time, migration files should be automatically created to update the existing version of the database: for example, a field was added (automatically resolved), the field was renamed (ask the user in the console), etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question