]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
- add a little step to get PG to work rudimentally, however
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 9 Nov 2014 03:42:07 +0000 (22:42 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 9 Nov 2014 03:42:07 +0000 (22:42 -0500)
the drop + recreate routine still needs a solution for refernential
integrity for it to be of general use

alembic/batch.py
alembic/ddl/impl.py
alembic/ddl/postgresql.py
tests/test_batch.py

index a64d2bcef95f9bcf0120ea617d695a70d1ff7a16..8470404a2c49ba175657ac276c6d992b881972ac 100644 (file)
@@ -170,6 +170,8 @@ class ApplyBatchImpl(object):
 
     def _create(self, op_impl):
         self._transfer_elements_to_new_table()
+
+        op_impl.prep_table_for_batch(self.table)
         op_impl.create_table(self.new_table)
 
         op_impl._exec(
index ca656771905576b129fb4cf122ff53a929d79581..da7705259d635b9932ca8b944061e4c331a4f585 100644 (file)
@@ -74,6 +74,16 @@ class DefaultImpl(with_metaclass(ImplMeta)):
         """
         return False
 
+    def prep_table_for_batch(self, table):
+        """perform any operations needed on a table before a new
+        one is created to replace it in batch mode.
+
+        the PG dialect uses this to drop constraints on the table
+        before the new one uses those same names.
+
+        """
+
+
     @property
     def bind(self):
         return self.connection
index 6193cda7c4b3b88d9d3594b3505593f5ff40b638..5156ceafa30f856770771c638c8284a95d5141e1 100644 (file)
@@ -14,6 +14,10 @@ class PostgresqlImpl(DefaultImpl):
     __dialect__ = 'postgresql'
     transactional_ddl = True
 
+    def prep_table_for_batch(self, table):
+        for constraint in table.constraints:
+            self.drop_constraint(constraint)
+
     def compare_server_default(self, inspector_column,
                                metadata_column,
                                rendered_metadata_default,
index 2d9bb512c8fd2408ae7e4df6a0d7e45eccd050cc..bbbb0943d50ff522c9019193bb438361e0ebfaa1 100644 (file)
@@ -362,6 +362,7 @@ class BatchRoundTripTest(TestBase):
             Column('x', Integer)
         )
         t1.create(self.conn)
+
         self.conn.execute(
             t1.insert(),
             [
@@ -409,6 +410,18 @@ class BatchRoundTripTest(TestBase):
             {"id": 5, "x": 9}
         ])
 
+    def test_drop_column_fk_recreate(self):
+        with self.op.batch_alter_table("foo", recreate='always') as batch_op:
+            batch_op.drop_column('data')
+
+        self._assert_data([
+            {"id": 1, "x": 5},
+            {"id": 2, "x": 6},
+            {"id": 3, "x": 7},
+            {"id": 4, "x": 8},
+            {"id": 5, "x": 9}
+        ])
+
     def test_rename_column(self):
         with self.op.batch_alter_table("foo") as batch_op:
             batch_op.alter_column('x', new_column_name='y')
@@ -496,6 +509,3 @@ class BatchRoundTripPostgresqlTest(BatchRoundTripTest):
     def test_change_type(self):
         super(BatchRoundTripPostgresqlTest, self).test_change_type()
 
-    @exclusions.fails()
-    def test_add_column_recreate(self):
-        super(BatchRoundTripPostgresqlTest, self).test_add_column_recreate()