Skip to content

Commit

Permalink
Add db migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosenpfand committed Jul 26, 2023
1 parent c51236a commit 0fe16c1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tool/migrate_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from sqlalchemy import create_engine, select
from app.db import BaseModel
import os


def migrate(url_from, url_to):
engine_from = create_engine(url_from)
engine_to = create_engine(url_to)

with engine_from.connect() as conn_lite:
with engine_to.connect() as conn_cloud:
for table in BaseModel.metadata.sorted_tables:
data = [dict(row) for row in conn_lite.execute(select(table.c))]
conn_cloud.execute(table.insert().values(data))


if __name__ == "__main__":
url_from = os.getenv("URL_FROM")
url_to = os.getenv("URL_TO")
migrate(url_from, url_to)

0 comments on commit 0fe16c1

Please sign in to comment.