Allow SQLite import onto a freshly seeded Postgres instance.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
ea38528ecf
commit
0ef3e3bb7a
|
|
@ -149,12 +149,18 @@ def migrate(sqlite_path: Path, media_src: Path, media_dest: Path, replace: bool)
|
||||||
stats: dict[str, tuple[int, int]] = {}
|
stats: dict[str, tuple[int, int]] = {}
|
||||||
try:
|
try:
|
||||||
existing = pg.execute("SELECT COUNT(*) FROM profiles").fetchone()[0]
|
existing = pg.execute("SELECT COUNT(*) FROM profiles").fetchone()[0]
|
||||||
|
seeds = pg.execute("SELECT COUNT(*) FROM tiers").fetchone()[0]
|
||||||
if existing and not replace:
|
if existing and not replace:
|
||||||
raise SystemExit(
|
raise SystemExit(
|
||||||
f"PostgreSQL already has {existing} profiles. Pass --replace after a probe copy, not on the only backup."
|
f"PostgreSQL already has {existing} profiles. Pass --replace after a probe copy, not on the only backup."
|
||||||
)
|
)
|
||||||
if existing and replace:
|
if seeds and not replace:
|
||||||
print(f"Replacing {existing} existing Postgres profiles")
|
raise SystemExit(
|
||||||
|
"PostgreSQL already has platform seeds from startup. "
|
||||||
|
"Pass --replace to load a SQLite snapshot onto this instance (no user profiles yet is OK)."
|
||||||
|
)
|
||||||
|
if replace:
|
||||||
|
print(f"Replacing Postgres snapshot (profiles={existing}, seed_tiers={seeds})")
|
||||||
for table in reversed(TABLES):
|
for table in reversed(TABLES):
|
||||||
pg.execute(f"TRUNCATE TABLE {table} CASCADE")
|
pg.execute(f"TRUNCATE TABLE {table} CASCADE")
|
||||||
|
|
||||||
|
|
@ -179,6 +185,10 @@ def migrate(sqlite_path: Path, media_src: Path, media_dest: Path, replace: bool)
|
||||||
count = pg.execute(f"SELECT COUNT(*) FROM {table}").fetchone()[0]
|
count = pg.execute(f"SELECT COUNT(*) FROM {table}").fetchone()[0]
|
||||||
print(f" {table}: {len(rows)} → {count}")
|
print(f" {table}: {len(rows)} → {count}")
|
||||||
stats[table] = (len(rows), int(count))
|
stats[table] = (len(rows), int(count))
|
||||||
|
pg.execute(
|
||||||
|
"INSERT INTO schema_migrations (id) VALUES (%s) ON CONFLICT (id) DO NOTHING",
|
||||||
|
("022_postgres_runtime_baseline",),
|
||||||
|
)
|
||||||
pg.commit()
|
pg.commit()
|
||||||
except Exception:
|
except Exception:
|
||||||
pg.rollback()
|
pg.rollback()
|
||||||
|
|
@ -195,6 +205,9 @@ def verify(stats: dict[str, tuple[int, int]]) -> None:
|
||||||
failed = False
|
failed = False
|
||||||
print("\nVerification")
|
print("\nVerification")
|
||||||
for table, (src, dest) in stats.items():
|
for table, (src, dest) in stats.items():
|
||||||
|
if table == "schema_migrations" and dest == src + 1:
|
||||||
|
print(f" ok {table:36} sqlite={src:5} postgres={dest:5} (incl. 022)")
|
||||||
|
continue
|
||||||
mark = "ok" if src == dest else "MISMATCH"
|
mark = "ok" if src == dest else "MISMATCH"
|
||||||
if src != dest:
|
if src != dest:
|
||||||
failed = True
|
failed = True
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user