Server: basic implementation. Not tested => no python installed; bugfix in ESP (uvicorn on port 8090)
This commit is contained in:
1 parent
3694cdf207
commit
8a51e3d95e
38 files changed
+2442
-21
No files matched your search
@@ -0,0 +1,63 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from logging.config import fileConfig
|
||||
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
|
||||
from poorbird.config import get_settings
|
||||
from poorbird.models import Base
|
||||
|
||||
config = context.config
|
||||
|
||||
if config.config_file_name is not None:
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
# One source of truth for the URL: the environment, via Settings. An explicit
|
||||
# override still wins, so tests can point a run at a scratch database.
|
||||
if not config.get_main_option("sqlalchemy.url", None):
|
||||
config.set_main_option("sqlalchemy.url", get_settings().database_url)
|
||||
|
||||
target_metadata = Base.metadata
|
||||
|
||||
OPTS = {"compare_type": True, "compare_server_default": True}
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
context.configure(
|
||||
url=config.get_main_option("sqlalchemy.url"),
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
**OPTS,
|
||||
)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def _run(connection) -> None:
|
||||
context.configure(connection=connection, target_metadata=target_metadata, **OPTS)
|
||||
with context.begin_transaction():
|
||||
context.run_migrations()
|
||||
|
||||
|
||||
def run_migrations_online() -> None:
|
||||
# A caller may hand us a live connection (the schema-drift test does).
|
||||
injected = config.attributes.get("connection", None)
|
||||
if injected is not None:
|
||||
_run(injected)
|
||||
return
|
||||
|
||||
connectable = engine_from_config(
|
||||
config.get_section(config.config_ini_section, {}),
|
||||
prefix="sqlalchemy.",
|
||||
poolclass=pool.NullPool,
|
||||
)
|
||||
with connectable.connect() as connection:
|
||||
_run(connection)
|
||||
|
||||
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
@@ -0,0 +1,26 @@
|
||||
"""${message}
|
||||
|
||||
Revision ID: ${up_revision}
|
||||
Revises: ${down_revision | comma,n}
|
||||
Create Date: ${create_date}
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
${imports if imports else ""}
|
||||
|
||||
revision: str = ${repr(up_revision)}
|
||||
down_revision: str | None = ${repr(down_revision)}
|
||||
branch_labels: str | Sequence[str] | None = ${repr(branch_labels)}
|
||||
depends_on: str | Sequence[str] | None = ${repr(depends_on)}
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
${upgrades if upgrades else "pass"}
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
${downgrades if downgrades else "pass"}
|
||||
@@ -0,0 +1,42 @@
|
||||
"""Baseline schema: SPEC 3 plus the SPEC 0 additions.
|
||||
|
||||
Revision ID: 0001
|
||||
Revises:
|
||||
Create Date: 2026-09-20
|
||||
|
||||
This baseline builds the schema from ``Base.metadata`` rather than from
|
||||
hand-written DDL. That is a deliberate, bounded exception, and it applies to
|
||||
this revision only:
|
||||
|
||||
* it cannot drift from the models, which hand-written DDL silently can;
|
||||
* ``tests/test_schema_matches_models.py`` asserts that a freshly migrated
|
||||
database produces an empty autogenerate diff, so the guarantee is checked
|
||||
rather than assumed;
|
||||
* every subsequent revision is a normal autogenerated one with real
|
||||
``op.*`` operations.
|
||||
|
||||
If you would rather have explicit DDL here, run
|
||||
``alembic revision --autogenerate`` against an empty database once Postgres is
|
||||
up and replace this file with the result. The drift test passes either way.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
|
||||
from poorbird.models import Base
|
||||
|
||||
revision: str = "0001"
|
||||
down_revision: str | None = None
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
Base.metadata.create_all(bind=op.get_bind())
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
Base.metadata.drop_all(bind=op.get_bind())
|
||||
Reference in new issue
Block a user