14.2.1. camcops_server.alembic.env


Copyright (C) 2012-2019 Rudolf Cardinal (rudolf@pobox.com).

This file is part of CamCOPS.

CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <http://www.gnu.org/licenses/>.

This file configures and runs Alembic.

It is loaded directly by Alembic, via a pseudo-“main” environment.

camcops_server.alembic.env.debug_op_object(op: Union[typing.List, alembic.operations.ops.OpContainer, typing.Tuple], level: int = 0) → str[source]

Describes a OpContainer.

camcops_server.alembic.env.filter_column_ops(column_ops: Iterable[alembic.operations.ops.AlterColumnOp], upgrade: bool, debug: bool = False) → Generator[[alembic.operations.ops.AlterColumnOp, NoneType], NoneType][source]

Generates column operations removing redundant changes from one type to an equivalent type, as judged by types_equivalent().

camcops_server.alembic.env.filter_table_ops(table_ops: Iterable[alembic.operations.ops.ModifyTableOps], upgrade: bool) → Generator[[alembic.operations.ops.ModifyTableOps, NoneType], NoneType][source]

Generates table operations, removing those that fail filter_column_ops().

camcops_server.alembic.env.process_revision_directives(context_: alembic.runtime.migration.MigrationContext, revision: Tuple[str], directives: List[alembic.operations.ops.MigrationScript]) → None[source]

Process autogenerated migration scripts and fix these problems.

camcops_server.alembic.env.run_migrations_offline(config: alembic.config.Config, target_metadata: sqlalchemy.sql.schema.MetaData) → None[source]

Run migrations in ‘offline’ mode.

This configures the context with just a URL and not an Engine, though an Engine is acceptable here as well. By skipping the Engine creation we don’t even need a DBAPI to be available.

Calls to context.execute() here emit the given string to the script output.

camcops_server.alembic.env.run_migrations_online(config: alembic.config.Config, target_metadata: sqlalchemy.sql.schema.MetaData) → None[source]

Run migrations in ‘online’ mode.

In this scenario we need to create an Engine and associate a connection with the context.

camcops_server.alembic.env.types_equivalent(database_type: sqlalchemy.sql.type_api.TypeEngine, metadata_type: sqlalchemy.sql.type_api.TypeEngine) → bool[source]

Are two types equivalent?

  • database_type – a type reflected from the database
  • metadata_type – a type from the SQLAlchemy metadata

equivalent, in a non-trivial way?

Specifically, it detects:

  • MySQL TINYINT(1) is equivalent to SQLAlchemy Boolean(), because TINYINT(1) is the correct instantiation of Boolean().
  • LONGTEXT(collation='utf8mb4_unicode_ci') is the MySQL database version of UnicodeText(length=4294967295)