Is it possible to use the first “database” approach in ruby ​​on rails?

Is it possible to create a db schema in the mysql GUI admin and then create (or update) a model based on this schema?

+4
source share
2 answers

This requires migration. When you learn DSL, recording migration (for example, with built-in generators) is much simpler than using a graphical interface to create tables. See the migration guide for more information.

ActiveRecord already does a lot of things automatically based on a database schema, such as adding column-based getters and setters. I'm not sure what you like best, so I don’t know how to help you.

+4
source

Migrations may seem confusing at first glance, but once you get used to them, migration naturally works in Rails. If you are mistaken in the name, you simply roll back and fix the migration file. Or write another moment that fixes the error in the rare case when you used it on db production.

They give you much more energy, especially if your project has gone through several stages of the version. You can roll back and transfer to any previous state at any time, and when you add new columns, you can easily set default values ​​or write short ruby ​​scripts that adjust values ​​or relationships.

0
source

All Articles