cardinal_pythonlib.sqlalchemy.alembic_ops


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, specifically to support view creation.

From https://alembic.readthedocs.org/en/latest/cookbook.html.

HAS NO TYPE ANNOTATIONS - Alembic uses inspect.getargspec(), which chokes on them.

class cardinal_pythonlib.sqlalchemy.alembic_ops.CreateSPOp(target)[source]

Represents CREATE FUNCTION (reversed by DROP FUNCTION) [sp = stored procedure].

Parameters:

target – instance of ReplaceableObject

reverse()[source]
Returns:

the MigrateOperation representing the reverse of this operation

class cardinal_pythonlib.sqlalchemy.alembic_ops.CreateViewOp(target)[source]

Represents CREATE VIEW (reversed by DROP VIEW).

Parameters:

target – instance of ReplaceableObject

reverse()[source]
Returns:

the MigrateOperation representing the reverse of this operation

class cardinal_pythonlib.sqlalchemy.alembic_ops.DropSPOp(target)[source]

Represents DROP FUNCTION (reversed by CREATE FUNCTION) [sp = stored procedure].

Parameters:

target – instance of ReplaceableObject

reverse()[source]
Returns:

the MigrateOperation representing the reverse of this operation

class cardinal_pythonlib.sqlalchemy.alembic_ops.DropViewOp(target)[source]

Represents DROP VIEW (reversed by CREATE VIEW).

Parameters:

target – instance of ReplaceableObject

reverse()[source]
Returns:

the MigrateOperation representing the reverse of this operation

class cardinal_pythonlib.sqlalchemy.alembic_ops.ReversibleOp(target)[source]

Represents a DDL (SQL) migration operation that can be reversed; e.g. the combination of CREATE VIEW and DROP VIEW.

Parameters:

target – instance of ReplaceableObject

classmethod invoke_for_target(operations, target)[source]

This method is proxied on the Operations class, via the Operations.drop_sp() method.

classmethod replace(operations, target, replaces=None, replace_with=None)[source]

This method is proxied on the Operations class, via the Operations.replace_sp() method.

reverse()[source]
Returns:

the MigrateOperation representing the reverse of this operation

cardinal_pythonlib.sqlalchemy.alembic_ops.create_sp(operations, operation)[source]

Implements CREATE FUNCTION.

Parameters:
  • operations – instance of alembic.operations.base.Operations

  • operation – instance of ReversibleOp

Returns:

None

cardinal_pythonlib.sqlalchemy.alembic_ops.create_view(operations, operation)[source]

Implements CREATE VIEW.

Parameters:
  • operations – instance of alembic.operations.base.Operations

  • operation – instance of ReversibleOp

Returns:

None

cardinal_pythonlib.sqlalchemy.alembic_ops.drop_sp(operations, operation)[source]

Implements DROP FUNCTION.

Parameters:
  • operations – instance of alembic.operations.base.Operations

  • operation – instance of ReversibleOp

Returns:

None

cardinal_pythonlib.sqlalchemy.alembic_ops.drop_view(operations, operation)[source]

Implements DROP VIEW.

Parameters:
  • operations – instance of alembic.operations.base.Operations

  • operation – instance of ReversibleOp

Returns:

None