-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from lsst-sqre/tickets/DM-48385
DM-48385: Add Alembic integration
- Loading branch information
Showing
25 changed files
with
619 additions
and
271 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
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,15 @@ | ||
[alembic] | ||
script_location = %(here)s/alembic | ||
file_template = %%(year)d%%(month).2d%%(day).2d_%%(hour).2d%%(minute).2d_%%(rev)s_%%(slug)s | ||
prepend_sys_path = . | ||
timezone = UTC | ||
version_path_separator = os | ||
|
||
[post_write_hooks] | ||
hooks = ruff ruff_format | ||
ruff.type = exec | ||
ruff.executable = ruff | ||
ruff.options = check --fix REVISION_SCRIPT_FILENAME | ||
ruff_format.type = exec | ||
ruff_format.executable = ruff | ||
ruff_format.options = format REVISION_SCRIPT_FILENAME |
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 @@ | ||
Generic single-database configuration. |
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,22 @@ | ||
"""Alembic migration environment.""" | ||
|
||
from alembic import context | ||
from safir.database import run_migrations_offline, run_migrations_online | ||
from safir.logging import configure_alembic_logging, configure_logging | ||
|
||
from timessquare.config import config | ||
from timessquare.dbschema import Base | ||
|
||
# Configure structlog. | ||
configure_logging(name="timessquare", log_level=config.log_level) | ||
configure_alembic_logging() | ||
|
||
# Run the migrations. | ||
if context.is_offline_mode(): | ||
run_migrations_offline(Base.metadata, config.database_url) | ||
else: | ||
run_migrations_online( | ||
Base.metadata, | ||
config.database_url, | ||
config.database_password, | ||
) |
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,26 @@ | ||
"""${message} | ||
|
||
Revision ID: ${up_revision} | ||
Revises: ${down_revision | comma,n} | ||
Create Date: ${create_date} | ||
""" | ||
|
||
from collections.abc import Sequence | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
${imports if imports else ""} | ||
|
||
# revision identifiers, used by Alembic. | ||
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"} |
69 changes: 69 additions & 0 deletions
69
alembic/versions/20250110_2121_487195933fee_initial_schema.py
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,69 @@ | ||
"""Initial schema. | ||
Revision ID: 487195933fee | ||
Revises: | ||
Create Date: 2025-01-10 21:21:26.706763+00:00 | ||
""" | ||
|
||
from collections.abc import Sequence | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "487195933fee" | ||
down_revision: str | None = None | ||
branch_labels: str | Sequence[str] | None = None | ||
depends_on: str | Sequence[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.create_table( | ||
"pages", | ||
sa.Column("name", sa.Unicode(length=32), nullable=False), | ||
sa.Column("ipynb", sa.UnicodeText(), nullable=False), | ||
sa.Column("parameters", sa.JSON(), nullable=False), | ||
sa.Column("title", sa.UnicodeText(), nullable=False), | ||
sa.Column("date_added", sa.DateTime(), nullable=False), | ||
sa.Column("authors", sa.JSON(), nullable=False), | ||
sa.Column("tags", sa.JSON(), nullable=False), | ||
sa.Column("uploader_username", sa.Unicode(length=64), nullable=True), | ||
sa.Column("date_deleted", sa.DateTime(), nullable=True), | ||
sa.Column("description", sa.UnicodeText(), nullable=True), | ||
sa.Column("cache_ttl", sa.Integer(), nullable=True), | ||
sa.Column("github_owner", sa.Unicode(length=255), nullable=True), | ||
sa.Column("github_repo", sa.Unicode(length=255), nullable=True), | ||
sa.Column("github_commit", sa.Unicode(length=40), nullable=True), | ||
sa.Column( | ||
"repository_path_prefix", sa.Unicode(length=2048), nullable=True | ||
), | ||
sa.Column( | ||
"repository_display_path_prefix", | ||
sa.Unicode(length=2048), | ||
nullable=True, | ||
), | ||
sa.Column( | ||
"repository_path_stem", sa.Unicode(length=255), nullable=True | ||
), | ||
sa.Column( | ||
"repository_source_extension", | ||
sa.Unicode(length=255), | ||
nullable=True, | ||
), | ||
sa.Column( | ||
"repository_sidecar_extension", | ||
sa.Unicode(length=255), | ||
nullable=True, | ||
), | ||
sa.Column( | ||
"repository_source_sha", sa.Unicode(length=40), nullable=True | ||
), | ||
sa.Column( | ||
"repository_sidecar_sha", sa.Unicode(length=40), nullable=True | ||
), | ||
sa.PrimaryKeyConstraint("name"), | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_table("pages") |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.