This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
The following commit(s) were added to refs/heads/main by this push:
new 8c15c3c Add a migration to use a database state subdirectory
8c15c3c is described below
commit 8c15c3c0f6787cb0d65be74f9ed6267ed2d421ea
Author: Sean B. Palmer <[email protected]>
AuthorDate: Thu Jan 15 19:58:44 2026 +0000
Add a migration to use a database state subdirectory
---
alembic.ini | 2 +-
atr/config.py | 2 +-
atr/db/__init__.py | 1 +
atr/server.py | 21 +++++++++++++++++++++
4 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/alembic.ini b/alembic.ini
index 1d4fffc..fd53b0f 100644
--- a/alembic.ini
+++ b/alembic.ini
@@ -67,7 +67,7 @@ version_path_separator = os
# Despite the three slashes, this is a relative path
# This is hardcoded, but env.py uses the actual configured ATR path
-sqlalchemy.url = sqlite:///state/atr.db
+sqlalchemy.url = sqlite:///state/database/atr.db
[post_write_hooks]
diff --git a/atr/config.py b/atr/config.py
index 1bd905d..46f1b66 100644
--- a/atr/config.py
+++ b/atr/config.py
@@ -73,7 +73,7 @@ class AppConfig:
# TODO: We need to get Puppet to check SVN out initially, or do it manually
SVN_STORAGE_DIR = os.path.join(STATE_DIR, "svn")
ATTESTABLE_STORAGE_DIR = os.path.join(STATE_DIR, "attestable")
- SQLITE_DB_PATH = decouple.config("SQLITE_DB_PATH", default="atr.db")
+ SQLITE_DB_PATH = decouple.config("SQLITE_DB_PATH",
default="database/atr.db")
STORAGE_AUDIT_LOG_FILE = os.path.join(STATE_DIR, "audit",
"storage-audit.log")
PERFORMANCE_LOG_FILE = os.path.join(STATE_DIR, "route-performance.log")
diff --git a/atr/db/__init__.py b/atr/db/__init__.py
index 050f307..b491589 100644
--- a/atr/db/__init__.py
+++ b/atr/db/__init__.py
@@ -772,6 +772,7 @@ class Session(sqlalchemy.ext.asyncio.AsyncSession):
async def create_async_engine(app_config: type[config.AppConfig]) ->
sqlalchemy.ext.asyncio.AsyncEngine:
absolute_db_path = os.path.join(app_config.STATE_DIR,
app_config.SQLITE_DB_PATH)
+ os.makedirs(os.path.dirname(absolute_db_path), exist_ok=True)
# Three slashes are required before either a relative or absolute path
sqlite_url = f"sqlite+aiosqlite:///{absolute_db_path}"
# Use aiosqlite for async SQLite access
diff --git a/atr/server.py b/atr/server.py
index e22eb3d..56590ca 100644
--- a/atr/server.py
+++ b/atr/server.py
@@ -114,6 +114,7 @@ def _app_dirs_setup(app_config: type[config.AppConfig]) ->
None:
directories_to_ensure = [
pathlib.Path(app_config.STATE_DIR) / "audit",
pathlib.Path(app_config.STATE_DIR) / "cache",
+ pathlib.Path(app_config.STATE_DIR) / "database",
util.get_downloads_dir(),
util.get_finished_dir(),
util.get_tmp_dir(),
@@ -503,6 +504,25 @@ def _migrate_cache(state_dir: pathlib.Path) -> None:
)
+def _migrate_database(state_dir: pathlib.Path, app_config:
type[config.AppConfig]) -> None:
+ configured_path = app_config.SQLITE_DB_PATH
+ if configured_path not in ("atr.db", "database/atr.db"):
+ raise RuntimeError(
+ f"SQLITE_DB_PATH is set to '{configured_path}' but migration only
supports "
+ f"the default value 'atr.db'. Please manually migrate your
database to "
+ f"'database/atr.db' and update SQLITE_DB_PATH, or remove the
custom setting."
+ )
+ _migrate_file(
+ state_dir / "atr.db",
+ state_dir / "database" / "atr.db",
+ )
+ for suffix in ["-shm", "-wal"]:
+ old_path = state_dir / f"atr.db{suffix}"
+ new_path = state_dir / "database" / f"atr.db{suffix}"
+ if old_path.exists():
+ _migrate_file(old_path, new_path)
+
+
def _migrate_directory(old_path: pathlib.Path, new_path: pathlib.Path) -> None:
if old_path.exists() and (not new_path.exists()):
old_path.rename(new_path)
@@ -535,6 +555,7 @@ def _migrate_state_directory(app_config:
type[config.AppConfig]) -> None:
try:
_migrate_audit(state_dir)
_migrate_cache(state_dir)
+ _migrate_database(state_dir, app_config)
finally:
fcntl.flock(lock_file, fcntl.LOCK_UN)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]