question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(edited by @grigi ) Migrations is currently planned as a post-v1.0 feature.

Some useful resources for getting this working right now:

Forward migrations

Best guess at this time for a complete solution, not a “quick” solution:

  • Make the describe_model() contain all the data one needs to generate DDL from.
  • Generate a sequence of high-level DDL instructions from describe_model()
  • Port generate_schema to use this high-level DDL instructions to generate a schema in the requested dialect. (This would require some decoupling from the driver instance, look at #72)
  • Build a persistance model (read/write) for high-level DDL insctuctions much like Django Migrations
  • And need a way to run “management” commands. So possibly a standard command-line utility.
  • Build a full model (e.g. same format as describe_model())from a series of high-level DDL instructions (as in read the migration persistance model)
  • Diff models, and generate a diff DDL instruction set.
  • If a Diff requires a default not pre-specified, we need to ask the user for something.
  • Have some way of determining the “version” of the models persisted in the DB.
  • Put it all together and make it work

I’m not particularily happy about many migration systems storing state in the DB itself, as for some environments that won’t work, but it is a very good place from a consistency PoV. We should have a backup for when we generate DDL that one would pass on to the DB team in cases where DDL changes have an established process (e.g. enterprise/consulting)

Data migrations

Proper data migration management makes this very useful:

  • Allow custom user scripts as migrations
  • Allow data-migrations to get a version of a model as it was at that time. So ability to build a model class from the intermediate describe_model() data
  • Handle DB edge cases, like Postgres being able to do DDL changes in a transaction OR data changes in a transaction, but not both.

Backward migrations

There is some cases where backwards migrations cannot be done as a forward migration clobbered/destroyed some data. In cases where we detect that we need mising data, and request a sane default. What do we do about data migrations? Is it safe to just emit a warning?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:23
  • Comments:32 (23 by maintainers)

github_iconTop GitHub Comments

34reactions
long2icecommented, May 25, 2020

Hey guys, I’m excited to announce that now we have a migrate tool written by pure python and just for tortoise-orm.🎉

Which named aerich.😜

Now it support MySQL, but is easy to extend postgres and sqlite.💪 Now it support MySQL & sqlite & Postgres, but the latter two need more tests.

That is a young project and must be lacking and exists bugs, PR and issues and star are welcome!

repo: https://github.com/long2ice/aerich

10reactions
long2icecommented, Mar 23, 2020

I write a manage.py script to make migrations for tortoise-orm,depend on dbmate and schemalex.

Requirements

  • dbmate, just install with brew install dbmate.
  • schemalex, just install with brew install schemalex.

Usage

just support makemigrations,migrate,rollback,initdb now

  • python manage.py -h
usage: manage.py [-h] {makemigrations,migrate,rollback,initdb} ...

optional arguments:
  -h, --help            show this help message and exit

subcommands:
  {makemigrations,migrate,rollback,initdb}

Link

https://gist.github.com/long2ice/0c9153d70fa2a08ec177fb2643820f3b

Hope to useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrations: A Novel: 9781250204028: McConaghy, Charlotte
When Franny's dark secrets catch up with her, how much is she willing to risk for one more chance at redemption?
Read more >
Migrations by Charlotte McConaghy - Goodreads
The novel tells the story of Franny Stone, an Irish woman living in a future world where all the wild animals are gone....
Read more >
Migrations - Macmillan
Epic and intimate, heartbreaking and galvanizing, Charlotte McConaghy's Migrations is an ode to a disappearing world and a breathtaking ...
Read more >
Migrations a book by Charlotte McConaghy - Bookshop
"Migrations is a gripping tale that ultimately celebrates the beauty and resilience of the creatures--human and animal--that endure." ... "An exceptional novel ...
Read more >
Migrations Overview - EF Core | Microsoft Learn
The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found