ctran / annotate_models

Annotate Rails classes with schema and routes info
Other
4.41k stars 598 forks source link

Output columns in database schema order, not A-Z order. #998

Open PeterTakahashi opened 11 months ago

PeterTakahashi commented 11 months ago

Currently, when columns appear in the model, they are output in A-Z order. I would like the output to be in the order of the columns in the database. This is because I design my models with strict control over the order of columns in the database.

For example, date columns such as created_at and updated_at should be placed last in the table, and foreign keys such as user_id should be placed above them.

Commands

Version

oskarpearson commented 9 months ago

I've had problems with this in the past because, in reality, people run database migrations in different orders.

Let's say we have three developers working at the same time

Consider this timeline:

Monday

Tuesday

Every time Developer 2 runs db:migrate and annotate runs, it'll show a 'diff' on developer 2, since their local table is out of order. The only way out of this is to db rollback, and then roll forwards, or reset their db entirely.

Why do this at all?

I'm not convinced there's a lot of value to trying to manage the order of columns in the database. Unless you have an exceptional situation, you're micro-optimising for very little benefit.