diff options
Diffstat (limited to 'alembic')
-rw-r--r-- | alembic/batch.py | 10 | ||||
-rw-r--r-- | alembic/ddl/postgresql.py | 3 | ||||
-rw-r--r-- | alembic/operations.py | 21 | ||||
-rw-r--r-- | alembic/testing/requirements.py | 11 |
4 files changed, 35 insertions, 10 deletions
diff --git a/alembic/batch.py b/alembic/batch.py index 1006739..6f6306b 100644 --- a/alembic/batch.py +++ b/alembic/batch.py @@ -23,7 +23,7 @@ class BatchOperationsImpl(object): self.recreate = recreate self.copy_from = copy_from self.table_args = table_args - self.table_kwargs = table_kwargs + self.table_kwargs = dict(table_kwargs) self.reflect_args = reflect_args self.reflect_kwargs = reflect_kwargs self.naming_convention = naming_convention @@ -139,11 +139,15 @@ class ApplyBatchImpl(object): for idx in self.table.indexes: self.indexes[idx.name] = idx + for k in self.table.kwargs: + self.table_kwargs.setdefault(k, self.table.kwargs[k]) + def _transfer_elements_to_new_table(self): assert self.new_table is None, "Can only create new table once" m = MetaData() schema = self.table.schema + self.new_table = new_table = Table( '_alembic_batch_temp', m, *(list(self.columns.values()) + list(self.table_args)), @@ -264,6 +268,10 @@ class ApplyBatchImpl(object): def add_constraint(self, const): if not const.name: raise ValueError("Constraint must have a name") + if isinstance(const, sql_schema.PrimaryKeyConstraint): + if self.table.primary_key in self.unnamed_constraints: + self.unnamed_constraints.remove(self.table.primary_key) + self.named_constraints[const.name] = const def drop_constraint(self, const): diff --git a/alembic/ddl/postgresql.py b/alembic/ddl/postgresql.py index 9f97b34..faeabad 100644 --- a/alembic/ddl/postgresql.py +++ b/alembic/ddl/postgresql.py @@ -23,7 +23,8 @@ class PostgresqlImpl(DefaultImpl): def prep_table_for_batch(self, table): for constraint in table.constraints: - self.drop_constraint(constraint) + if constraint.name is not None: + self.drop_constraint(constraint) def compare_server_default(self, inspector_column, metadata_column, diff --git a/alembic/operations.py b/alembic/operations.py index 2bf8060..dcacd06 100644 --- a/alembic/operations.py +++ b/alembic/operations.py @@ -67,11 +67,12 @@ class Operations(object): def _primary_key_constraint(self, name, table_name, cols, schema=None): m = self._metadata() columns = [sa_schema.Column(n, NULLTYPE) for n in cols] - t1 = sa_schema.Table(table_name, m, - *columns, - schema=schema) - p = sa_schema.PrimaryKeyConstraint(*columns, name=name) - t1.append_constraint(p) + t = sa_schema.Table( + table_name, m, + *columns, + schema=schema) + p = sa_schema.PrimaryKeyConstraint(*[t.c[n] for n in cols], name=name) + t.append_constraint(p) return p def _foreign_key_constraint(self, name, source, referent, @@ -1356,7 +1357,7 @@ class BatchOperations(Operations): return super(BatchOperations, self).drop_column( self.impl.table_name, column_name, schema=self.impl.schema) - def create_primary_key(self, name, cols): + def create_primary_key(self, name, cols, **kw): """Issue a "create primary key" instruction using the current batch migration context. @@ -1368,7 +1369,9 @@ class BatchOperations(Operations): :meth:`.Operations.create_primary_key` """ - raise NotImplementedError("not yet implemented") + kw['schema'] = self.impl.schema + return super(BatchOperations, self).create_primary_key( + name, self.impl.table_name, cols, **kw) def create_foreign_key( self, name, referent, local_cols, remote_cols, **kw): @@ -1422,7 +1425,9 @@ class BatchOperations(Operations): :meth:`.Operations.create_check_constraint` """ - raise NotImplementedError("not yet implemented") + kw['schema'] = self.impl.schema + return super(BatchOperations, self).create_check_constraint( + name, self.impl.table_name, condition, **kw) def drop_constraint(self, name, type_=None): """Issue a "drop constraint" instruction using the diff --git a/alembic/testing/requirements.py b/alembic/testing/requirements.py index b981951..2889ea5 100644 --- a/alembic/testing/requirements.py +++ b/alembic/testing/requirements.py @@ -32,6 +32,17 @@ class SuiteRequirements(Requirements): ) @property + def check_constraints_w_enforcement(self): + """Target database must support check constraints + and also enforce them.""" + + return exclusions.open() + + @property + def reflects_pk_names(self): + return exclusions.closed() + + @property def fail_before_sqla_079(self): return exclusions.fails_if( lambda config: not util.sqla_079, |