Skip to content

Commit

Permalink
Update base.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gitofanindya authored Nov 27, 2024
1 parent 5cb1590 commit 78faced
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions nxdrive/dao/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,17 @@ def __init__(self, db: Path, /) -> None:
print(f"Create {type(self).__name__} on {self.db!r}")

exists = self.db.is_file()
print(f"------ exists 1: {exists!r}")
if exists:
# Fix potential file corruption
try:
fix_db(self.db)
except DatabaseError:
# The file is too damaged, we'll try and restore a backup.
exists = self.restore_backup()
print(f"------ exists 2: {exists!r}")
if not exists:
self.db.unlink(missing_ok=True)

self._engine_uid = self.db.stem.replace("ndrive_", "")
self.in_tx: Optional[int] = None
self._tx_lock = RLock()
Expand All @@ -84,17 +85,20 @@ def __init__(self, db: Path, /) -> None:
raise RuntimeError("Unable to connect to database.")
c = self.conn.cursor()
self._init_db(c)

schema_version = 0
if exists:
schema_version = self.get_schema_version(c, exists)
print(f"------ schema_version 1: {schema_version!r}")
else:
self.set_schema_version(c, schema_version)
print(f"------ schema_version 2: {schema_version!r}")
try:
self._migrate_db(schema_version)
except Exception:
print("---- migration_success = False")

Check warning on line 98 in nxdrive/dao/base.py

View check run for this annotation

Codecov / codecov/patch

nxdrive/dao/base.py#L98

Added line #L98 was not covered by tests
self.migration_success = False
else:
print("---- migration_success = True")
self.migration_success = True

def __repr__(self) -> str:
Expand Down Expand Up @@ -196,7 +200,7 @@ def _migrate_table(self, cursor: Cursor, name: str, /) -> None:
print(f">>>> Altered table: {name!r} to {tmpname!r}")

# Because Windows don't release the table, force the creation
print(f">>>> calling _create_table: {name!r}")
print(f">>>> calling _create_table [BASE]: {name!r}")
self._create_table(cursor, name, force=True)
print(">>>> called _create_table")
print(f">>>> Inserting into: {name!r}")
Expand All @@ -219,10 +223,13 @@ def _migrate_table(self, cursor: Cursor, name: str, /) -> None:
print(f">>>> Droping table: {tmpname!r}")
print(">>>> issue <<<<")
# cursor.execute(f"DROP TABLE {tmpname}")
cursor.execute(f"DROP TABLE {tmpname}")
"""
try:
cursor.execute(f"DROP TABLE {tmpname}")
except Exception as e:
print(f"EXCEPTION 2: {e!r}")
print(f"EXCEPTION while droping {tmpname!r} 2: {e!r}")
"""
print(f">>>> Dropped table 2.: {tmpname!r}")
print("----END----")

Expand Down

0 comments on commit 78faced

Please sign in to comment.