예제 #1
0
    def test_swap_two_cols_in_src(self):
        """Swap the position of 2 columns in the dest table"""

        self.src.columns._sequence[1], self.src.columns._sequence[
            5] = self.src.columns._sequence[5], self.src.columns._sequence[1]

        for i, (p, r) in enumerate(
                syncdb.sync_modified_columns(self.src.columns,
                                             self.dest.columns,
                                             sync_comments=True)):
            if i == 0:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `staff_id` TINYINT(3) UNSIGNED NOT NULL AFTER `rental_id`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `staff_id` TINYINT(3) UNSIGNED NOT NULL AFTER `return_date`"
                )

            if i == 1:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `return_date`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`"
                )

        self.assertEqual(i, 1)
예제 #2
0
    def test_sync_multiple_modified_columns(self):
        """Test: multiple columns in src table have been modified in dest table (ignore Column COMMENT)"""
        self.dest.columns['rental_date'].type = "TEXT"
        self.dest.columns['rental_date'].null = True
        self.dest.columns['rental_date'].comment = "hello world"
        self.dest.columns['return_date'].type = "TIMESTAMP"

        for i, (p, r) in enumerate(
                syncdb.sync_modified_columns(self.src.columns,
                                             self.dest.columns,
                                             sync_comments=False)):
            if i == 0:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `rental_date` TEXT NULL AFTER `rental_id`")
            if i == 1:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `return_date` DATETIME NULL AFTER `customer_id`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `return_date` TIMESTAMP NULL AFTER `customer_id`"
                )

        self.assertEqual(i, 1)
예제 #3
0
    def test_sync_modified_column(self):
        """Test: column in src table have been modified in dest table (ignore Column COMMENT)"""
        self.dest.columns['rental_date'].type = "TEXT"
        self.dest.columns['rental_date'].null = True
        self.dest.columns['rental_date'].comment = "hello world"

        for i, (p,r) in enumerate(syncdb.sync_modified_columns(self.src.columns, self.dest.columns, sync_comments=False)):
            self.assertEqual(p, "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`")
            self.assertEqual(r, "MODIFY COLUMN `rental_date` TEXT NULL AFTER `rental_id`")

        self.assertEqual(i, 0)
예제 #4
0
    def test_move_col_to_beg_in_src(self):
        """Move a column in the dest table towards the begining of the column list"""

        tmp = self.src.columns._sequence[4]
        self.src.columns._sequence.remove(tmp)
        self.src.columns._sequence.insert(1, tmp)

        for i, (p,r) in enumerate(syncdb.sync_modified_columns(self.src.columns, self.dest.columns, sync_comments=True)):
            if i == 0:
                self.assertEqual(p, "MODIFY COLUMN `return_date` DATETIME NULL AFTER `rental_id`")
                self.assertEqual(r, "MODIFY COLUMN `return_date` DATETIME NULL AFTER `customer_id`")

        self.assertEqual(i, 0)
예제 #5
0
    def test_move_col_to_end_in_dest(self):
        """Move a column in the dest table towards the end of the column list"""

        tmp = self.dest.columns._sequence[1]
        self.dest.columns._sequence.remove(tmp)
        self.dest.columns._sequence.insert(5, tmp)

        for i, (p,r) in enumerate(syncdb.sync_modified_columns(self.src.columns, self.dest.columns, sync_comments=True)):
            if i == 0:
                self.assertEqual(p, "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`")
                self.assertEqual(r, "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `staff_id`")

        self.assertEqual(i, 0)
예제 #6
0
    def test_swap_two_cols_in_dest(self):
        """Swap the position of 2 columns in the dest table"""

        self.dest.columns._sequence[1], self.dest.columns._sequence[5] = self.dest.columns._sequence[5], self.dest.columns._sequence[1]

        for i, (p,r) in enumerate(syncdb.sync_modified_columns(self.src.columns, self.dest.columns, sync_comments=True)):
            if i == 0:
                self.assertEqual(p, "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`")
                self.assertEqual(r, "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `return_date`")
            if i == 1:
                self.assertEqual(p, "MODIFY COLUMN `staff_id` TINYINT(3) UNSIGNED NOT NULL AFTER `return_date`")
                self.assertEqual(r, "MODIFY COLUMN `staff_id` TINYINT(3) UNSIGNED NOT NULL AFTER `rental_id`")

        self.assertEqual(i, 1)
예제 #7
0
    def test_sync_multiple_modified_columns(self):
        """Test: multiple columns in src table have been modified in dest table (ignore Column COMMENT)"""
        self.dest.columns['rental_date'].type = "TEXT"
        self.dest.columns['rental_date'].null = True
        self.dest.columns['rental_date'].comment = "hello world"
        self.dest.columns['return_date'].type = "TIMESTAMP"
        
        for i, (p,r) in enumerate(syncdb.sync_modified_columns(self.src.columns, self.dest.columns, sync_comments=False)):
            if i == 0:
                self.assertEqual(p, "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`")
                self.assertEqual(r, "MODIFY COLUMN `rental_date` TEXT NULL AFTER `rental_id`")
            if i == 1:
                self.assertEqual(p, "MODIFY COLUMN `return_date` DATETIME NULL AFTER `customer_id`")
                self.assertEqual(r, "MODIFY COLUMN `return_date` TIMESTAMP NULL AFTER `customer_id`")

        self.assertEqual(i, 1)
예제 #8
0
    def test_sync_modified_column(self):
        """Test: column in src table have been modified in dest table (ignore Column COMMENT)"""
        self.dest.columns['rental_date'].type = "TEXT"
        self.dest.columns['rental_date'].null = True
        self.dest.columns['rental_date'].comment = "hello world"

        for i, (p, r) in enumerate(
                syncdb.sync_modified_columns(self.src.columns,
                                             self.dest.columns,
                                             sync_comments=False)):
            self.assertEqual(
                p,
                "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`"
            )
            self.assertEqual(
                r, "MODIFY COLUMN `rental_date` TEXT NULL AFTER `rental_id`")

        self.assertEqual(i, 0)
예제 #9
0
    def test_move_3_cols_in_src(self):
        """Move around 3 columns in the dest table"""

        self.src.columns._sequence[0], self.src.columns._sequence[
            3] = self.src.columns._sequence[3], self.src.columns._sequence[0]
        tmp = self.src.columns._sequence[1]
        self.src.columns._sequence.remove(tmp)
        self.src.columns._sequence.insert(2, tmp)

        for i, (p, r) in enumerate(
                syncdb.sync_modified_columns(self.src.columns,
                                             self.dest.columns,
                                             sync_comments=True)):
            if i == 0:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `customer_id` SMALLINT(5) UNSIGNED NOT NULL FIRST"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `customer_id` SMALLINT(5) UNSIGNED NOT NULL AFTER `inventory_id`"
                )

            if i == 1:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `inventory_id` MEDIUMINT(8) UNSIGNED NOT NULL AFTER `customer_id`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `inventory_id` MEDIUMINT(8) UNSIGNED NOT NULL AFTER `rental_date`"
                )

            if i == 2:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `inventory_id`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`"
                )

        self.assertEqual(i, 2)
예제 #10
0
    def test_swap_pairs_of_cols_in_dest(self):
        """Swap the position of 2 pairs of columns in the dest table"""

        a,b = self.dest.columns._sequence[1], self.dest.columns._sequence[2]
        self.dest.columns._sequence[1], self.dest.columns._sequence[2] = self.dest.columns._sequence[4], self.dest.columns._sequence[5]
        self.dest.columns._sequence[4], self.dest.columns._sequence[5] = a,b

        for i, (p,r) in enumerate(syncdb.sync_modified_columns(self.src.columns, self.dest.columns, sync_comments=True)):
            if i == 0:
                self.assertEqual(p, "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`")
                self.assertEqual(r, "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `customer_id`")
            if i == 1:
                self.assertEqual(p, "MODIFY COLUMN `inventory_id` MEDIUMINT(8) UNSIGNED NOT NULL AFTER `rental_date`")
                self.assertEqual(r, "MODIFY COLUMN `inventory_id` MEDIUMINT(8) UNSIGNED NOT NULL AFTER `rental_date`")
            if i == 2:
                self.assertEqual(p, "MODIFY COLUMN `customer_id` SMALLINT(5) UNSIGNED NOT NULL AFTER `inventory_id`")
                self.assertEqual(r, "MODIFY COLUMN `customer_id` SMALLINT(5) UNSIGNED NOT NULL AFTER `staff_id`")

        self.assertEqual(i, 2)
예제 #11
0
    def test_move_3_cols_in_dest(self):
        """Move around 3 columns in the dest table"""

        self.dest.columns._sequence[0], self.dest.columns._sequence[3] = self.dest.columns._sequence[3], self.dest.columns._sequence[0]
        tmp = self.dest.columns._sequence[1]
        self.dest.columns._sequence.remove(tmp)
        self.dest.columns._sequence.insert(2, tmp)

        for i, (p,r) in enumerate(syncdb.sync_modified_columns(self.src.columns, self.dest.columns, sync_comments=True)):
            if i == 0:
                self.assertEqual(p, "MODIFY COLUMN `rental_id` INT(11) NOT NULL auto_increment FIRST")
                self.assertEqual(r, "MODIFY COLUMN `rental_id` INT(11) NOT NULL auto_increment AFTER `rental_date`")
            if i == 1:
                self.assertEqual(p, "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`")
                self.assertEqual(r, "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `inventory_id`")
            if i == 2:
                self.assertEqual(p, "MODIFY COLUMN `inventory_id` MEDIUMINT(8) UNSIGNED NOT NULL AFTER `rental_date`")
                self.assertEqual(r, "MODIFY COLUMN `inventory_id` MEDIUMINT(8) UNSIGNED NOT NULL AFTER `customer_id`")

        self.assertEqual(i, 2)
예제 #12
0
    def test_swap_pairs_of_cols_in_dest(self):
        """Swap the position of 2 pairs of columns in the dest table"""

        a, b = self.dest.columns._sequence[1], self.dest.columns._sequence[2]
        self.dest.columns._sequence[1], self.dest.columns._sequence[
            2] = self.dest.columns._sequence[4], self.dest.columns._sequence[5]
        self.dest.columns._sequence[4], self.dest.columns._sequence[5] = a, b

        for i, (p, r) in enumerate(
                syncdb.sync_modified_columns(self.src.columns,
                                             self.dest.columns,
                                             sync_comments=True)):
            if i == 0:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `customer_id`"
                )
            if i == 1:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `inventory_id` MEDIUMINT(8) UNSIGNED NOT NULL AFTER `rental_date`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `inventory_id` MEDIUMINT(8) UNSIGNED NOT NULL AFTER `rental_date`"
                )
            if i == 2:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `customer_id` SMALLINT(5) UNSIGNED NOT NULL AFTER `inventory_id`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `customer_id` SMALLINT(5) UNSIGNED NOT NULL AFTER `staff_id`"
                )

        self.assertEqual(i, 2)
예제 #13
0
    def test_move_col_to_beg_in_src(self):
        """Move a column in the dest table towards the begining of the column list"""

        tmp = self.src.columns._sequence[4]
        self.src.columns._sequence.remove(tmp)
        self.src.columns._sequence.insert(1, tmp)

        for i, (p, r) in enumerate(
                syncdb.sync_modified_columns(self.src.columns,
                                             self.dest.columns,
                                             sync_comments=True)):
            if i == 0:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `return_date` DATETIME NULL AFTER `rental_id`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `return_date` DATETIME NULL AFTER `customer_id`"
                )

        self.assertEqual(i, 0)
예제 #14
0
    def test_move_col_to_end_in_dest(self):
        """Move a column in the dest table towards the end of the column list"""

        tmp = self.dest.columns._sequence[1]
        self.dest.columns._sequence.remove(tmp)
        self.dest.columns._sequence.insert(5, tmp)

        for i, (p, r) in enumerate(
                syncdb.sync_modified_columns(self.src.columns,
                                             self.dest.columns,
                                             sync_comments=True)):
            if i == 0:
                self.assertEqual(
                    p,
                    "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `rental_id`"
                )
                self.assertEqual(
                    r,
                    "MODIFY COLUMN `rental_date` DATETIME NOT NULL AFTER `staff_id`"
                )

        self.assertEqual(i, 0)