Skip to content

Commit 34517dd

Browse files
committed
Update pyproject.toml and Alembic configuration
- Added author information to pyproject.toml. - Included project URLs for repository, documentation, issues, changelog, contributing, and license in pyproject.toml. - Enhanced Alembic migration configuration to support both in-memory and file-based SQLite databases, improving flexibility for testing and deployment.
1 parent b7ef483 commit 34517dd

2 files changed

Lines changed: 44 additions & 15 deletions

File tree

backend/alembic/env.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
def get_url() -> str:
2121
"""
2222
Database URL for migrations. Uses DB_PATH from app config so we migrate the same DB the app uses.
23-
Tests can override with config.set_main_option("sqlalchemy.url", "sqlite:///:memory:").
23+
Tests can override with config.set_main_option("sqlalchemy.url", "sqlite:///path" or "sqlite:///:memory:").
2424
"""
2525
url_from_config = config.get_main_option("sqlalchemy.url")
26-
if url_from_config and ":memory:" in url_from_config:
26+
if url_from_config:
2727
return url_from_config
2828
db_path = Path(DB_PATH).resolve()
2929
return f"sqlite:///{db_path.as_posix()}"
@@ -43,11 +43,37 @@ def run_migrations_offline() -> None:
4343

4444
def run_migrations_online() -> None:
4545
url_from_config = config.get_main_option("sqlalchemy.url")
46-
# Prefer app DB_PATH so we migrate the same DB the app uses (alembic.ini may have a different path)
47-
use_app_path = True
48-
if url_from_config and ":memory:" in url_from_config:
49-
use_app_path = False # tests override with in-memory DB
50-
if use_app_path:
46+
# Use url_from_config when set (tests or explicit override); otherwise use app DB_PATH
47+
if url_from_config:
48+
url_str: str = url_from_config
49+
if ":memory:" in url_str:
50+
configuration = config.get_section(config.config_ini_section) or {}
51+
configuration["sqlalchemy.url"] = url_str
52+
connectable = engine_from_config(
53+
configuration,
54+
prefix="sqlalchemy.",
55+
poolclass=pool.NullPool,
56+
)
57+
else:
58+
# File path: extract path and use creator so SQLite creates the file
59+
path_str = url_str.replace("sqlite:///", "").replace("sqlite://", "")
60+
path_obj = Path(path_str)
61+
if not path_obj.is_absolute():
62+
# Resolve relative to the directory containing alembic.ini so
63+
# "data.sqlite" in backend/alembic.ini -> backend/data.sqlite
64+
config_dir = Path(config.config_file_name or "").resolve().parent
65+
path_obj = (config_dir / path_str).resolve()
66+
path_obj.parent.mkdir(parents=True, exist_ok=True)
67+
68+
def _sqlite_creator():
69+
return sqlite3.connect(str(path_obj))
70+
71+
connectable = create_engine(
72+
"sqlite://",
73+
creator=_sqlite_creator,
74+
poolclass=pool.NullPool,
75+
)
76+
else:
5177
db_path = Path(DB_PATH).resolve()
5278
db_path.parent.mkdir(parents=True, exist_ok=True)
5379
path_str = str(db_path)
@@ -60,14 +86,6 @@ def _sqlite_creator():
6086
creator=_sqlite_creator,
6187
poolclass=pool.NullPool,
6288
)
63-
else:
64-
configuration = config.get_section(config.config_ini_section) or {}
65-
configuration["sqlalchemy.url"] = url_from_config
66-
connectable = engine_from_config(
67-
configuration,
68-
prefix="sqlalchemy.",
69-
poolclass=pool.NullPool,
70-
)
7189

7290
with connectable.connect() as connection:
7391
context.configure(

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ version = "0.4.0"
88
description = "Telegram bot for processing invoices via OCR and storing them in SQLite"
99
requires-python = ">=3.11"
1010
readme = "README.md"
11+
authors = [
12+
{ name = "Ama", email = "amalsdev367@gmail.com" },
13+
]
1114
dependencies = [
1215
"aiogram>=3.10",
1316
"aiosqlite>=0.20.0",
@@ -37,6 +40,14 @@ dev = [
3740
[project.scripts]
3841
invoiceflowbot = "bot:main"
3942

43+
[project.urls]
44+
repository = "https://github.com/AmaLS367/InvoiceFlowBot"
45+
documentation = "https://github.com/AmaLS367/InvoiceFlowBot/blob/main/docs/README.md"
46+
issues = "https://github.com/AmaLS367/InvoiceFlowBot/issues"
47+
changelog = "https://github.com/AmaLS367/InvoiceFlowBot/blob/main/CHANGELOG.md"
48+
contributing = "https://github.com/AmaLS367/InvoiceFlowBot/blob/main/CONTRIBUTING.md"
49+
license = "https://github.com/AmaLS367/InvoiceFlowBot/blob/main/LICENSE"
50+
4051
[tool.setuptools]
4152
packages = [
4253
"backend",

0 commit comments

Comments
 (0)