1

I have this tables I created models for using vanilla SQLAlchemy to operate the postgre DB.

class table:

   def __init__(self):

    self.engine = create_engine(DB_ADDRESS, poolclass=NullPool)
    self.meta = MetaData()

    self.table = Table(
        "employeetable",
        self.meta,
        Column("id", Integer, primary_key=True),
        Column("employeeId", String),
        Column("name", String),
        Column("email", String),
        Column("place", String),
        Column("sector", String),
        Column("function", String),
        Column("phone", String),
        Column("status", String),
        Column("type", String),
        Column(
            "lastChange",
            DateTime(timezone=True),
            server_default=func.now(),
        ),
        Column("receptorId", String),
        Column("syncFlag", Boolean),
    )

    self.meta.create_all(self.engine)

each class also have its methods for me to search and alter the the table and whatnot. The table already is populated with data and takes care of the data sync between two systems. The problem is now I need to add another column to check the sync of another field. I know I have to migrate the table to do this, and also know Alembic is an option to this. I just can't figure out how I get Alembic to "import" this class/table so I can work with it inside Alembic to make this migration to alter the table.

Can someone give me some directions on how this works and how i can configure it to receive this?

gsab
  • 11
  • 4
  • The documentation for [autogenerate](https://alembic.sqlalchemy.org/en/latest/autogenerate.html) describes how point alembic to the model(s) in your project. – Gord Thompson Oct 22 '21 at 17:02
  • @GordThompson I think I understand now how to auto(re)generate the schemas inside alembic, do I lose the data I have on the table or does it just models it and restablishes the connection and schema through Alembic? My main concern Is passing the model and this data as it is very important to this sync. After the first one is no big deal as I would just create a nullable column with every line nullified and fix the table update and read methods slightly to see it. The sync script would do everything else out of the DBs. – gsab Oct 22 '21 at 18:34
  • Alembic only emits DDL (data definition language) statements like `ALTER TABLE`. It doesn't affect the data *within* a table unless you drop a column (or a whole table) in which case the data (obviously) goes away. – Gord Thompson Oct 22 '21 at 18:53

0 Answers0