コード例 #1
0
    def test_sync_modified_fk(self):
        """Test: src table has foreign keys modified in dest table"""
        self.dest.foreign_keys['fk_rental_customer'].delete_rule = "SET NULL"

        for i, (p,r) in enumerate(syncdb.sync_modified_constraints(self.src.foreign_keys, self.dest.foreign_keys)):
            if i==0:
                self.assertEqual(p, "DROP FOREIGN KEY `fk_rental_customer`")
                self.assertEqual(r, "DROP FOREIGN KEY `fk_rental_customer`")
            if i==1:
                self.assertEqual(p, "ADD CONSTRAINT `fk_rental_customer` FOREIGN KEY `fk_rental_customer` (`customer_id`) REFERENCES `customer` (`customer_id`) ON DELETE RESTRICT ON UPDATE CASCADE")
                self.assertEqual(r, "ADD CONSTRAINT `fk_rental_customer` FOREIGN KEY `fk_rental_customer` (`customer_id`) REFERENCES `customer` (`customer_id`) ON DELETE SET NULL ON UPDATE CASCADE")

        self.assertEqual(i, 1)
コード例 #2
0
    def test_sync_modified_index(self):
        """Test: src table has indexes modified in dest table"""
        self.dest.indexes['idx_fk_customer_id'].kind = "UNIQUE"
        self.dest.indexes['idx_fk_customer_id'].fields = [('inventory_id', 0)]

        for i, (p,r) in enumerate(syncdb.sync_modified_constraints(self.src.indexes, self.dest.indexes)):
            if i==0:
                self.assertEqual(p, "DROP INDEX `idx_fk_customer_id`")
                self.assertEqual(r, "DROP INDEX `idx_fk_customer_id`")
            if i==1:
                self.assertEqual(p, "ADD INDEX `idx_fk_customer_id` (`customer_id`) USING BTREE")
                self.assertEqual(r, "ADD UNIQUE INDEX `idx_fk_customer_id` (`inventory_id`) USING BTREE")

        self.assertEqual(i, 1)
コード例 #3
0
    def test_sync_modified_fk(self):
        """Test: src table has foreign keys modified in dest table"""
        self.dest.foreign_keys['fk_rental_customer'].delete_rule = "SET NULL"

        for i, (p, r) in enumerate(
                syncdb.sync_modified_constraints(self.src.foreign_keys,
                                                 self.dest.foreign_keys)):
            if i == 0:
                self.assertEqual(p, "DROP FOREIGN KEY `fk_rental_customer`")
                self.assertEqual(r, "DROP FOREIGN KEY `fk_rental_customer`")
            if i == 1:
                self.assertEqual(
                    p,
                    "ADD CONSTRAINT `fk_rental_customer` FOREIGN KEY `fk_rental_customer` (`customer_id`) REFERENCES `customer` (`customer_id`) ON DELETE RESTRICT ON UPDATE CASCADE"
                )
                self.assertEqual(
                    r,
                    "ADD CONSTRAINT `fk_rental_customer` FOREIGN KEY `fk_rental_customer` (`customer_id`) REFERENCES `customer` (`customer_id`) ON DELETE SET NULL ON UPDATE CASCADE"
                )

        self.assertEqual(i, 1)
コード例 #4
0
    def test_sync_modified_index(self):
        """Test: src table has indexes modified in dest table"""
        self.dest.indexes['idx_fk_customer_id'].kind = "UNIQUE"
        self.dest.indexes['idx_fk_customer_id'].fields = [('inventory_id', 0)]

        for i, (p, r) in enumerate(
                syncdb.sync_modified_constraints(self.src.indexes,
                                                 self.dest.indexes)):
            if i == 0:
                self.assertEqual(p, "DROP INDEX `idx_fk_customer_id`")
                self.assertEqual(r, "DROP INDEX `idx_fk_customer_id`")
            if i == 1:
                self.assertEqual(
                    p,
                    "ADD INDEX `idx_fk_customer_id` (`customer_id`) USING BTREE"
                )
                self.assertEqual(
                    r,
                    "ADD UNIQUE INDEX `idx_fk_customer_id` (`inventory_id`) USING BTREE"
                )

        self.assertEqual(i, 1)