coast icon indicating copy to clipboard operation
coast copied to clipboard

Automatic migration generation

Open Immortalin opened this issue 6 years ago • 5 comments

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.

Immortalin avatar May 19 '19 18:05 Immortalin

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 🤷‍♂️

swlkr avatar Aug 20 '19 21:08 swlkr

Maybe take a look at Django? They have had it for years.

Immortalin avatar Sep 06 '19 23:09 Immortalin

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:

  1. Create / change the Django models in Python *.py files
  2. Run makemigrations command to auto-generate intermediate migration .py files
  3. Run sqlmigrate to turn migration file to sql and do migration

In coast, what you do:

  1. Create a migration file in Clojure .clj file
  2. Run make migrate to turn migration file to sql and 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.

dawranliou avatar Oct 04 '19 22:10 dawranliou

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.

Immortalin avatar Oct 05 '19 04:10 Immortalin

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:

  1. Create/change the Django models in Python *.py files
  2. Run migrate to 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.

dawranliou avatar Oct 05 '19 17:10 dawranliou