Creating models from existing database #1356
Replies: 10 comments 4 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Has anything been done on this topic? I have a complete database in postgres and I would like to make a new api in Adonis, but I need not to have to define each model by hand, any suggestions please |
Beta Was this translation helpful? Give feedback.
-
Also have a need for this feature and would make my migration from Django to Adonis much easier! |
Beta Was this translation helpful? Give feedback.
-
Related #4017 |
Beta Was this translation helpful? Give feedback.
-
Would love to see this feature |
Beta Was this translation helpful? Give feedback.
-
Any update? |
Beta Was this translation helpful? Give feedback.
-
Is it still considered to be done? |
Beta Was this translation helpful? Give feedback.
-
any updates? |
Beta Was this translation helpful? Give feedback.
-
@thetutlage - are you still considering this? |
Beta Was this translation helpful? Give feedback.
-
Would also be interesting about this kind of functionality to keep models and tables in sync. |
Beta Was this translation helpful? Give feedback.
-
I receive a lot of requests asking to create migrations from models, just like the way Django does. I have a different take on this and sharing it here
Fundamentally, migrations and models are de-coupled in both AdonisJS and Django. For example: If you have an existing database, you can just create models and start using it without creating any migrations.
But Django does provide extra tooling to create migrations from the existing models, so basically you save some time in writing them by hand. I personally avoided it for couple of reasons.
data type (varchar)
,null constraints
,PK
,FK
or maybe evendatabase triggers
. I think this makes models fat, as you don't need half of this information at runtime (after migrations are done).But, I do believe in the idea of automating things with migrations and models. So I decided to later work on something that can create/update models from the existing database tables.
node ace make:models
and it creates all the models for you.node ace update:model
and it will reflect the changes without messing up with your custom code in that file.This approach will keep models simple (not configuring DB via models) + you are not defining columns by hand in the models and they are always up to date.
Again this also requires some effort, so de-prioritized over critical features
Beta Was this translation helpful? Give feedback.
All reactions