Files
reader-api/scripts/drop_legacy_import_tables.py
virtus 212d4df42f
Build and Push Reader API Image / docker (push) Successful in 38s
chore: remove legacy tables and series table scripts
- Removed mongoose dependency from package-lock.json.
- Deleted legacy import tables: ImportCandidateChapter, AssetNovelMapping, ImportJob, ImportSession, SourceAsset via new script `drop_legacy_import_tables.py`.
- Added script `drop_series_table.py` to drop the Series table.

Co-authored-by: Copilot <copilot@github.com>
2026-05-04 19:43:22 +07:00

36 lines
993 B
Python

import os
from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
from dotenv import load_dotenv
from sqlalchemy import create_engine, text
def main() -> None:
load_dotenv()
database_url = os.getenv("DATABASE_URL")
if not database_url:
raise RuntimeError("DATABASE_URL missing")
parts = urlsplit(database_url)
filtered_query = [(k, v) for (k, v) in parse_qsl(parts.query, keep_blank_values=True) if k.lower() != "schema"]
normalized_url = urlunsplit((parts.scheme, parts.netloc, parts.path, urlencode(filtered_query), parts.fragment))
engine = create_engine(normalized_url)
tables = [
"ImportCandidateChapter",
"AssetNovelMapping",
"ImportJob",
"ImportSession",
"SourceAsset",
]
with engine.begin() as conn:
for table in tables:
conn.execute(text(f'DROP TABLE IF EXISTS "{table}" CASCADE'))
print("Dropped legacy tables")
if __name__ == "__main__":
main()