cardinal_pythonlib.sqlalchemy.alembic_func


Original code copyright (C) 2009-2022 Rudolf Cardinal (rudolf@pobox.com).

This file is part of cardinal_pythonlib.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


Support functions for Alembic, the migration tool for SQLAlchemy.

cardinal_pythonlib.sqlalchemy.alembic_func.get_current_and_head_revision(database_url: str, alembic_config_filename: str, alembic_base_dir: str = None, version_table: str = 'alembic_version') → Tuple[str, str][source]

Returns a tuple of (current_revision, head_revision); see get_current_revision() and get_head_revision_from_alembic().

Parameters:
  • database_url – SQLAlchemy URL for the database
  • alembic_config_filename – config filename
  • alembic_base_dir – directory to start in, so relative paths in the config file work.
  • version_table – table name for Alembic versions
cardinal_pythonlib.sqlalchemy.alembic_func.get_current_revision(database_url: str, version_table: str = 'alembic_version') → str[source]

Ask the database what its current revision is.

Parameters:
  • database_url – SQLAlchemy URL for the database
  • version_table – table name for Alembic versions
cardinal_pythonlib.sqlalchemy.alembic_func.get_head_revision_from_alembic(alembic_config_filename: str, alembic_base_dir: str = None, version_table: str = 'alembic_version') → str[source]

Ask Alembic what its head revision is (i.e. where the Python code would like the database to be at).

Parameters:
  • alembic_config_filename – config filename
  • alembic_base_dir – directory to start in, so relative paths in the config file work.
  • version_table – table name for Alembic versions
cardinal_pythonlib.sqlalchemy.alembic_func.stamp_allowing_unusual_version_table(config: alembic.config.Config, revision: str, sql: bool = False, tag: str = None, version_table: str = 'alembic_version') → None[source]

Stamps the Alembic version table with the given revision; don’t run any migrations.

This function is a clone of alembic.command.stamp(), but allowing version_table to change. See https://alembic.zzzcomputing.com/en/latest/api/commands.html#alembic.command.stamp