0

I was using SQLAlchemy ORM to connect to a in memory database when I decided to implement a versioning tracking to the DB schema. To do this I've been following the tutorial on how to set up Versioning using SQLAlchemy, but now I'm wondering if there is a way for me to get my upgrade and downgrade scripts to also update/create my SQLAlchemy.orm tables?

I ask this because I now don't know how to write code using only SQLAlchemy Migrate since a developer might not know of the most recent change done to the database. Currently the developer just has to look at the file containing the class that maps to a table in the DB to know what is available, but from my understanding using Migrate would not synchronize these classes with the changes applied in a upgrade/downgrade script. This synchronization would need to be done manually. I looked at reflect but this doesn't seem to require prior knowledge as to the structure of the table.

I know I must be missing something. I could have my DB opened in HeidiSQL and [ALT + TAB] each time my memory wants to confirm something in the DB but this is slows me down a lot when I used to just be able to use auto complete on classes as I type (Note: I'm heavily dyslexic and I'm prone to many spelling mistakes which is why I auto complete drastically improves my productivity). Is there a way for the upgrade scripts to create/update/delete files containing ORM classes?

ie.

class ExtractionEvent(Base):
    __tablename__ = 'ExtractionEvents'
    Id = Column(Integer, primary_key=True, autoincrement=True)
    ...
Tolure
  • 859
  • 1
  • 14
  • 34
  • The way these migration tools usually work is that you update the ORM classes, and the tool updates the database objects, but it sounds like you want to update the database objects and have a tool update your ORM classes, is that right? – snakecharmerb Apr 23 '22 at 09:19
  • @snakecharmerb I decided for this change because I don't think there is a way to modify my ORM classes in such a way so that I don't lose data or that data gets migrated correctly (ie. Changing a string based date Field to an int Timestamp). I think having a DB created from ORM classes is much quicker and easier but I can see headaches if there's data that needs to be migrated as well. – Tolure Apr 23 '22 at 15:46
  • 1
    [This](https://pypi.org/project/sqlacodegen/) might work for you. – snakecharmerb Apr 23 '22 at 16:11

0 Answers0