Skip to content

Commit a1eb8d7

Browse files
committed
Update SQLite argument handling in migration script to accept bare file paths
1 parent 76104b4 commit a1eb8d7

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

scripts/migrate_sqlite_to_mysql.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def main() -> int:
101101
parser.add_argument(
102102
"--sqlite",
103103
required=True,
104-
metavar="URI",
105-
help="SQLAlchemy URI for the source SQLite DB (e.g. sqlite:////path/to/microsalt.db)",
104+
metavar="PATH_OR_URI",
105+
help="Path to the source SQLite file, or a full SQLAlchemy URI (e.g. sqlite:////path/to/microsalt.db)",
106106
)
107107
parser.add_argument(
108108
"--mysql",
@@ -117,12 +117,19 @@ def main() -> int:
117117
)
118118
args = parser.parse_args()
119119

120-
print(f"Source : {args.sqlite}")
120+
# Accept a bare file path as well as a full SQLAlchemy URI
121+
sqlite_uri = args.sqlite
122+
if not sqlite_uri.startswith("sqlite:"):
123+
import os
124+
125+
sqlite_uri = "sqlite:///" + os.path.abspath(sqlite_uri)
126+
127+
print(f"Source : {sqlite_uri}")
121128
print(f"Target : {args.mysql}")
122129
if args.dry_run:
123130
print("DRY RUN — no data will be written.\n")
124131

125-
src_engine = create_engine(args.sqlite, pool_pre_ping=True)
132+
src_engine = create_engine(sqlite_uri, pool_pre_ping=True)
126133
dst_engine = create_engine(args.mysql, pool_pre_ping=True)
127134

128135
# Ensure all ORM tables exist in the destination
@@ -133,11 +140,11 @@ def main() -> int:
133140
total_skipped = 0
134141

135142
with Session(src_engine) as src_session, Session(dst_engine) as dst_session:
143+
src_inspector = inspect(src_engine)
136144
for model in TABLES:
137145
table_name = model.__tablename__
138146

139147
# Check whether the table exists in the source at all
140-
src_inspector = inspect(src_engine)
141148
if table_name not in src_inspector.get_table_names():
142149
print(f" {table_name:<20} — not present in source, skipping")
143150
continue

0 commit comments

Comments
 (0)