diff --git a/tiled/_tests/test_utils.py b/tiled/_tests/test_utils.py index f31fe86b1..ab688d2b7 100644 --- a/tiled/_tests/test_utils.py +++ b/tiled/_tests/test_utils.py @@ -59,3 +59,13 @@ def test_ensure_specified_sql_driver(): ensure_specified_sql_driver("sqlite:///test.db") == "sqlite+aiosqlite:///test.db" ) + # Filepaths are implicitly SQLite databases. + # Relative path + assert ensure_specified_sql_driver("test.db") == "sqlite+aiosqlite:///test.db" + # Relative path anchored to . + assert ensure_specified_sql_driver("./test.db") == "sqlite+aiosqlite:///test.db" + # Absolute path + assert ( + ensure_specified_sql_driver("/tmp/test.db") + == "sqlite+aiosqlite:////tmp/test.db" + ) diff --git a/tiled/catalog/adapter.py b/tiled/catalog/adapter.py index 224e3b055..ee4c42ae5 100644 --- a/tiled/catalog/adapter.py +++ b/tiled/catalog/adapter.py @@ -64,7 +64,6 @@ from ..server.schemas import Asset, DataSource, Management, Revision, Spec from ..structures.core import StructureFamily from ..utils import ( - SCHEME_PATTERN, UNCHANGED, Conflicts, OneShotCachedMap, @@ -1367,9 +1366,6 @@ def from_uri( stderr = process.stderr.decode() logging.info(f"Subprocess stdout: {stdout}") logging.error(f"Subprocess stderr: {stderr}") - if not SCHEME_PATTERN.match(uri): - # Interpret URI as filepath. - uri = f"sqlite+aiosqlite:///{uri}" parsed_url = make_url(uri) if (parsed_url.get_dialect().name == "sqlite") and ( diff --git a/tiled/commandline/_catalog.py b/tiled/commandline/_catalog.py index 68e50dc70..2de6849b7 100644 --- a/tiled/commandline/_catalog.py +++ b/tiled/commandline/_catalog.py @@ -44,11 +44,8 @@ def init( from ..alembic_utils import UninitializedDatabase, check_database, stamp_head from ..catalog.alembic_constants import ALEMBIC_DIR, ALEMBIC_INI_TEMPLATE_PATH from ..catalog.core import ALL_REVISIONS, REQUIRED_REVISION, initialize_database - from ..utils import SCHEME_PATTERN, ensure_specified_sql_driver + from ..utils import ensure_specified_sql_driver - if not SCHEME_PATTERN.match(database): - # Interpret URI as filepath. - database = f"sqlite+aiosqlite:///{database}" database = ensure_specified_sql_driver(database) async def do_setup(): diff --git a/tiled/utils.py b/tiled/utils.py index eefdc9529..e404b97f3 100644 --- a/tiled/utils.py +++ b/tiled/utils.py @@ -738,7 +738,11 @@ def ensure_specified_sql_driver(uri: str) -> str: 'sqlite://...' -> 'sqlite+aiosqlite://...' 'postgresql+asyncpg://...' -> 'postgresql+asynpg://...' 'postgresql+my_custom_driver://...' -> 'postgresql+my_custom_driver://...' + '/path/to/file.db' -> 'sqlite+aiosqlite:////path/to/file.db' """ + if not SCHEME_PATTERN.match(uri): + # Interpret URI as filepath. + uri = f"sqlite+aiosqlite:///{Path(uri)}" scheme, rest = uri.split(":", 1) new_scheme = SCHEME_TO_SCHEME_PLUS_DRIVER.get(scheme, scheme) return ":".join([new_scheme, rest])