-
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 #225 from lsst-sqre/tickets/DM-46034
DM-46034: Add Alembic support
- Loading branch information
Showing
19 changed files
with
352 additions
and
148 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,22 @@ | ||
# Alembic configuration for vo-cutouts. | ||
# | ||
# This file does not retain the comments that are generated as part of the | ||
# default template, since they will get out of date with newer versions of | ||
# Alembic. See the Alembic documentation for details about each setting and | ||
# for settings that are not used here. | ||
|
||
[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,14 @@ | ||
# vo-cutouts Alembic configuration | ||
|
||
This directory contains the Alembic configuration for managing the vo-cutouts UWS database. | ||
It is installed into the vo-cutouts Docker image and is used to check whether the schema is up-to-date at startup of any vo-cutouts component. | ||
It is also used by the Helm hook that updates the vo-cutouts UWS schema if `config.updateSchema` is enabled. | ||
|
||
## Generating new migrations | ||
|
||
For detailed instructions on how to generate a new Alembic migration, see [the Safir documentation](https://safir.lsst.io/user-guide/database/schema#create-migration). | ||
|
||
One of the files in this directory is here only to support creating migrations. | ||
`docker-compose.yaml` is a [docker-compose](https://docs.docker.com/compose/) configuration file that starts a PostgreSQL instance suitable for generating schema migrations. | ||
This file is not used at runtime. | ||
It is used by the tox environment described in the above documentation. |
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,12 @@ | ||
version: "3" | ||
services: | ||
postgresql: | ||
image: "postgres:latest" | ||
hostname: "postgresql" | ||
container_name: "postgresql" | ||
environment: | ||
POSTGRES_PASSWORD: "INSECURE" | ||
POSTGRES_USER: "vo-cutouts" | ||
POSTGRES_DB: "vo-cutouts" | ||
ports: | ||
- "5432:5432" |
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 safir.database import run_migrations_offline, run_migrations_online | ||
from safir.logging import configure_alembic_logging, configure_logging | ||
from safir.uws import UWSSchemaBase | ||
|
||
from alembic import context | ||
from vocutouts.config import config | ||
|
||
# Configure structlog. | ||
configure_logging(name="vo-cutouts", log_level=config.log_level) | ||
configure_alembic_logging() | ||
|
||
# Run the migrations. | ||
if context.is_offline_mode(): | ||
run_migrations_offline(UWSSchemaBase.metadata, config.database_url) | ||
else: | ||
run_migrations_online( | ||
UWSSchemaBase.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 typing import Sequence, Union | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
${imports if imports else ""} | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = ${repr(up_revision)} | ||
down_revision: Union[str, None] = ${repr(down_revision)} | ||
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)} | ||
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)} | ||
|
||
|
||
def upgrade() -> None: | ||
${upgrades if upgrades else "pass"} | ||
|
||
|
||
def downgrade() -> None: | ||
${downgrades if downgrades else "pass"} |
27 changes: 27 additions & 0 deletions
27
alembic/versions/20240912_1902_5ab72a20365b_initial_uws_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,27 @@ | ||
"""Initial UWS schema | ||
Revision ID: 5ab72a20365b | ||
Revises: | ||
Create Date: 2024-09-12 19:02:23.855138+00:00 | ||
""" | ||
|
||
from collections.abc import Sequence | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "5ab72a20365b" | ||
down_revision: str | None = None | ||
branch_labels: str | Sequence[str] | None = None | ||
depends_on: str | Sequence[str] | None = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### |
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,3 @@ | ||
### New features | ||
|
||
- Use Alembic to manage the schema of the UWS database. When upgrading to this version, set `config.updateSchema` to true in the Helm configuration for the first deployment. This release contains no schema changes, but needs to perform a migration to add the Alembic version information. The vo-cutouts components will now refuse to start if the database schema has changed and the database has not yet been migrated. |
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.