Automatic migration generation
In Django, you can define the state of DB and have it generate the migration i.e. the diff automatically. This saves a lot of time. Many new ORMs like TypeORM supports both the Rails style and Django style of migrations.
I like the idea of this, but it seems like it will add quite a bit of complexity to the migration process. typeORM is super complex and it seems like to change names you need to fallback to regular migrations anyway.
I may get around to at least handling the easiest case for creating/dropping tables/columns/indexes, but I'm not sure when 🤷♂️
Maybe take a look at Django? They have had it for years.
I don't think this feature is that useful in Coast. Django and TypeORM migrations both rely on the model/entity/schema in the user's code. When you start a Django migration, you do:
- Create / change the Django models in Python
*.pyfiles - Run
makemigrationscommand to auto-generate intermediate migration.pyfiles - Run
sqlmigrateto turn migration file tosqland do migration
In coast, what you do:
- Create a migration file in Clojure
.cljfile - Run
make migrateto turn migration file tosqland do migration
If you think of the process, this is clear that the reason Coast doesn't need auto migration generation is because Coast doesn't have the schema/model files to start with.
In Coast, the db queries are very close to raw sql strings. I consider this a blessing because I don't really need the abstractions from ORMs. SQL is a very good abstraction for me most of the time.
Not really, in Django you can do python manage.py migrate directly. You can completely avoid dealing with the DB.
In more enterprise settings, there are technologies such as Skeema and SQL data tools to compare the before and end states of SQL schemas and generate the migrations automatically.
Not really, in Django you can do python manage.py migrate directly. You can completely avoid dealing with the DB.
My bad. I shall correct it to:
- Create/change the Django models in Python *.py files
- Run
migrateto migrate the db schema
I think I know your need a bit better now. Do you wish Coast has something similar to the Models in Django where you can update in place to reflect the real state of db schema, instead of defining the incremental migrations? For example, today, to add a role column into the user table, you need to create a migration file to do it. You wish that it can be done by updating a user.clj file in place.
Personally, I still prefer the current approach where the db schema is the only source of truth. I just need to connect to the database and check the schema when I need to. I don't really feel the need to have a second source of truth from the Django Models. Though this might be helpful in an enterprise setting where developers might take extra efforts to keep their development db schemas consistent.