diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-02-18 15:31:42 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-02-18 15:32:09 -0500 |
commit | 490d9fa42b095cedb17abee17a063ee108992959 (patch) | |
tree | 77732ba37c0d40bb787c2c8f30ec11a638d879cb /alembic/operations | |
parent | 8e5b861fd7d4a23b4575a17e5ef72d974680b441 (diff) | |
download | alembic-490d9fa42b095cedb17abee17a063ee108992959.tar.gz |
Use SQLAlchemy _copy() when available
Adjusted the use of SQLAlchemy's ".copy()" internals to use "._copy()"
for version 1.4.0, as this method is being renamed.
Change-Id: I1e69a1628e408f06b43efbc0cc52fc0ad1e8cbc4
Diffstat (limited to 'alembic/operations')
-rw-r--r-- | alembic/operations/batch.py | 15 | ||||
-rw-r--r-- | alembic/operations/toimpl.py | 3 |
2 files changed, 11 insertions, 7 deletions
diff --git a/alembic/operations/batch.py b/alembic/operations/batch.py index f029193..990b3a8 100644 --- a/alembic/operations/batch.py +++ b/alembic/operations/batch.py @@ -13,6 +13,7 @@ from sqlalchemy.util import topological from ..util import exc from ..util.sqla_compat import _columns_for_constraint +from ..util.sqla_compat import _copy from ..util.sqla_compat import _ensure_scope_for_ddl from ..util.sqla_compat import _fk_is_self_referential from ..util.sqla_compat import _insert_inline @@ -194,7 +195,7 @@ class ApplyBatchImpl(object): schema = self.table.schema self.columns = OrderedDict() for c in self.table.c: - c_copy = c.copy(schema=schema) + c_copy = _copy(c, schema=schema) c_copy.unique = c_copy.index = False # ensure that the type object was copied, # as we may need to modify it in-place @@ -297,16 +298,18 @@ class ApplyBatchImpl(object): # FK constraints from other tables; we assume SQLite # no foreign keys just keeps the names unchanged, so # when we rename back, they match again. - const_copy = const.copy( - schema=schema, target_table=self.table + const_copy = _copy( + const, schema=schema, target_table=self.table ) else: # "target_table" for ForeignKeyConstraint.copy() is # only used if the FK is detected as being # self-referential, which we are handling above. - const_copy = const.copy(schema=schema) + const_copy = _copy(const, schema=schema) else: - const_copy = const.copy(schema=schema, target_table=new_table) + const_copy = _copy( + const, schema=schema, target_table=new_table + ) if isinstance(const, ForeignKeyConstraint): self._setup_referent(m, const) new_table.append_constraint(const_copy) @@ -503,7 +506,7 @@ class ApplyBatchImpl(object): ) # we copy the column because operations.add_column() # gives us a Column that is part of a Table already. - self.columns[column.name] = column.copy(schema=self.table.schema) + self.columns[column.name] = _copy(column, schema=self.table.schema) self.column_transfers[column.name] = {} def drop_column(self, table_name, column, **kw): diff --git a/alembic/operations/toimpl.py b/alembic/operations/toimpl.py index c6dbafb..10a41e4 100644 --- a/alembic/operations/toimpl.py +++ b/alembic/operations/toimpl.py @@ -2,6 +2,7 @@ from sqlalchemy import schema as sa_schema from . import ops from .base import Operations +from ..util.sqla_compat import _copy @Operations.implementation_for(ops.AlterColumnOp) @@ -128,7 +129,7 @@ def add_column(operations, operation): kw = operation.kw if column.table is not None: - column = column.copy() + column = _copy(column) t = operations.schema_obj.table(table_name, column, schema=schema) operations.impl.add_column(table_name, column, schema=schema, **kw) |