2

Sometimes we want to share project code with DB migration scripts, e.g. utilities and models, for readability, usability, fast development and all that.

The issue is that each migration script should have its own copy of the shared code, or else we risk running past migrations with modified code. However, this creates a lot of overhead in copied only the used code and its dependencies, and avoiding mistakes.

The question is how to do this automatically? or better yet, am I wrong and should use a different approach?

Stack:

  • SQLAlchemy - orm
  • alembic - generate migration scripts in a versions directory inside our project
  • mysql
  • python3 of course
Sagi
  • 592
  • 5
  • 15
  • 1
    A revision control system and / or code versioning? – Klaus D. Dec 17 '18 at 07:02
  • @KlausD. would you suggest that the migration of latest code will address libraries of an earlier commit? – Mugen Dec 17 '18 at 07:41
  • You can create many scenario with simple `git`. Just to name two: 1. use a submodule to link a library revision to a project 2. use `pip install -e …` to install revisions of the lib from your git as dependencies… Whatever fits your project best. – Klaus D. Dec 17 '18 at 07:44
  • @KlausD. Are you suggesting checking out the revision of the project code for each migration script? It kinda ruins the flow when developing the scripts and running migrations locally. But it might just work. – Sagi Dec 17 '18 at 08:30
  • My advise can not be more substantial than the description of your requirements. So, it is very generic. – Klaus D. Dec 17 '18 at 08:44

0 Answers0