Skip to content

Commit

Permalink
Merge pull request #18 from demml/migration
Browse files Browse the repository at this point in the history
Update db_initializer.py
  • Loading branch information
thorrester committed May 9, 2024
2 parents 02bbc56 + a047128 commit 34e94dc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
21 changes: 7 additions & 14 deletions opsml/registry/sql/migration/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ script_location = alembic
# defaults to the current working directory.
prepend_sys_path = .

sqlalchemy.url = ""
# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python>=3.9 or backports.zoneinfo library.
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
# string value is passed to ZoneInfo()
# If specified, requires the python-dateutil library that can be
# installed by adding `alembic[tz]` to the pip requirements
# string value is passed to dateutil.tz.gettz()
# leave blank for localtime
# timezone =

Expand All @@ -36,10 +37,10 @@ prepend_sys_path = .
# sourceless = false

# version location specification; This defaults
# to alembic/versions. When using multiple version
# to migration/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
# version_locations = %(here)s/bar:%(here)s/bat:migration/versions

# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
Expand All @@ -60,8 +61,6 @@ version_path_separator = os # Use os.pathsep. Default configuration used for ne
# are written from script.py.mako
# output_encoding = utf-8

sqlalchemy.url = ""


[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
Expand All @@ -74,12 +73,6 @@ sqlalchemy.url = ""
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME

# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
# hooks = ruff
# ruff.type = exec
# ruff.executable = %(here)s/.venv/bin/ruff
# ruff.options = --fix REVISION_SCRIPT_FILENAME

# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic
Expand Down Expand Up @@ -113,4 +106,4 @@ formatter = generic

[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
datefmt = %H:%M:%S
20 changes: 16 additions & 4 deletions opsml/registry/sql/migration/alembic/env.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
import os
from logging.config import fileConfig

from alembic import context
from sqlalchemy import engine_from_config, pool

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config

# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
if config.attributes.get("configure_logger", True):
fileConfig(config.config_file_name)

# add your model's MetaData object here
# for 'autogenerate' support


# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
# target_metadata = Base.metadata

# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.


def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
Expand Down Expand Up @@ -47,7 +59,7 @@ def run_migrations_online() -> None:
connection = config.attributes.get("connection")
if connection is None:
engine = engine_from_config(
config.get_section(config.config_ini_section), # type: ignore
config.get_section(config.config_ini_section),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""Add interface types
"""update tables
Revision ID: 6e3a1f978946
Revision ID: c54a9fbab8dc
Revises:
Create Date: 2024-05-02 10:44:58.659238
Create Date: 2023-04-11 23:07:56.160420
"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

Expand All @@ -16,17 +14,15 @@
from opsml.types import CommonKwargs

logger = ArtifactLogger.get_logger()


# revision identifiers, used by Alembic.
revision: str = "6e3a1f978946"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
revision = "c54a9fbab8dc"
down_revision = None
branch_labels = None
depends_on = None


def upgrade() -> None:
logger.info("Alembic revision: Adding types to model and data registries - {}", revision)
logger.info("Alembic revision: Adding interface columns to model and data registries - {}", revision)
try:
bind = op.get_context().bind
insp = sa.inspect(bind)
Expand Down

0 comments on commit 34e94dc

Please sign in to comment.