-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sessions): alembic data migration queries for populating the pro…
…ject sessions table (#5539)
- Loading branch information
1 parent
16d9edd
commit 50f5794
Showing
5 changed files
with
452 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
from typing import Optional | ||
|
||
from alembic import command | ||
from alembic.config import Config | ||
from phoenix.config import ENV_PHOENIX_SQL_DATABASE_SCHEMA | ||
from sqlalchemy import Engine, Row, text | ||
|
||
|
||
def _up(engine: Engine, alembic_config: Config, revision: str) -> None: | ||
with engine.connect() as conn: | ||
alembic_config.attributes["connection"] = conn | ||
command.upgrade(alembic_config, revision) | ||
engine.dispose() | ||
assert _version_num(engine) == (revision,) | ||
|
||
|
||
def _down(engine: Engine, alembic_config: Config, revision: str) -> None: | ||
with engine.connect() as conn: | ||
alembic_config.attributes["connection"] = conn | ||
command.downgrade(alembic_config, revision) | ||
engine.dispose() | ||
assert _version_num(engine) == (None if revision == "base" else (revision,)) | ||
|
||
|
||
def _version_num(engine: Engine) -> Optional[Row[tuple[str]]]: | ||
schema_prefix = "" | ||
if engine.url.get_backend_name().startswith("postgresql"): | ||
assert (schema := os.environ[ENV_PHOENIX_SQL_DATABASE_SCHEMA]) | ||
schema_prefix = f"{schema}." | ||
table, column = "alembic_version", "version_num" | ||
stmt = text(f"SELECT {column} FROM {schema_prefix}{table}") | ||
with engine.connect() as conn: | ||
return conn.execute(stmt).first() |
Oops, something went wrong.