Ejemplo n.º 1
0
 def test_delete_fk_column(self):
     main_table = 'test_drop_foreign'
     ref_table = 'test_df_ref'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     db.delete_column(main_table, 'foreign_id')
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 0)
     db.delete_table(main_table)
     db.delete_table(ref_table)
Ejemplo n.º 2
0
 def test_rename_fk_column(self):
     main_table = 'test_rename_foreign'
     ref_table = 'test_rf_ref'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     db.rename_column(main_table, 'foreign_id', 'reference_id')
     db.execute_deferred_sql()  #Create constraints
     constraints = db._find_foreign_constraints(main_table, 'reference_id')
     self.assertEquals(len(constraints), 1)
     db.delete_table(main_table)
     db.delete_table(ref_table)
Ejemplo n.º 3
0
 def test_delete_fk_column(self):
     if db.backend_name != "mysql":
         return
     main_table = 'test_drop_foreign'
     ref_table = 'test_df_ref'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     db.delete_column(main_table, 'foreign_id')
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 0)
     db.delete_table(main_table)
     db.delete_table(ref_table)
Ejemplo n.º 4
0
 def test_rename_fk_column(self):
     if db.backend_name != "mysql":
         return
     main_table = 'test_rename_foreign'
     ref_table = 'test_rf_ref'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     db.rename_column(main_table, 'foreign_id', 'reference_id')
     db.execute_deferred_sql()  #Create constraints
     constraints = db._find_foreign_constraints(main_table, 'reference_id')
     self.assertEquals(len(constraints), 1)
     db.delete_table(main_table)
     db.delete_table(ref_table)
Ejemplo n.º 5
0
 def test_rename_constrained_table(self):
     """Renames a table with a foreign key column (towards another table)"""
     main_table = 'test_rn_table'
     ref_table = 'test_rt_ref'
     renamed_table = 'test_renamed_table'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     db.rename_table(main_table, renamed_table)
     db.execute_deferred_sql()  #Create constraints
     constraints = db._find_foreign_constraints(renamed_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     (rtable, rcolumn) = db._lookup_constraint_references(
             renamed_table, constraints[0])
     self.assertEquals(rcolumn, 'id')
     db.delete_table(renamed_table)
     db.delete_table(ref_table)
Ejemplo n.º 6
0
 def test_rename_constrained_table(self):
     """Renames a table with a foreign key column (towards another table)"""
     main_table = 'test_rn_table'
     ref_table = 'test_rt_ref'
     renamed_table = 'test_renamed_table'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     db.rename_table(main_table, renamed_table)
     db.execute_deferred_sql()  #Create constraints
     constraints = db._find_foreign_constraints(renamed_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     (rtable, rcolumn) = db._lookup_constraint_references(
             renamed_table, constraints[0])
     self.assertEquals(rcolumn, 'id')
     db.delete_table(renamed_table)
     db.delete_table(ref_table)
Ejemplo n.º 7
0
 def test_constraint_references(self):
     """Tests that referred table is reported accurately"""
     main_table = 'test_cns_ref'
     reference_table = 'test_cr_foreign'
     db.start_transaction()
     self._create_foreign_tables(main_table, reference_table)
     db.execute_deferred_sql()
     constraint = db._find_foreign_constraints(main_table, 'foreign_id')[0]
     references = db._lookup_constraint_references(main_table, constraint)
     self.assertEquals((reference_table, 'id'), references)
     db.delete_table(main_table)
     db.delete_table(reference_table)
Ejemplo n.º 8
0
 def test_constraint_references(self):
     """Tests that referred table is reported accurately"""
     main_table = 'test_cns_ref'
     reference_table = 'test_cr_foreign'
     db.start_transaction()
     self._create_foreign_tables(main_table, reference_table)
     db.execute_deferred_sql()
     constraint = db._find_foreign_constraints(main_table, 'foreign_id')[0]
     references = db._lookup_constraint_references(main_table, constraint)
     self.assertEquals((reference_table, 'id'), references)
     db.delete_table(main_table)
     db.delete_table(reference_table)
Ejemplo n.º 9
0
 def test_constraint_references(self):
     """Tests that referred table is reported accurately"""
     if db.backend_name != "mysql":
         return
     main_table = 'test_cns_ref'
     reference_table = 'test_cr_foreign'
     db.start_transaction()
     self._create_foreign_tables(main_table, reference_table)
     db.execute_deferred_sql()
     constraint = db._find_foreign_constraints(main_table, 'foreign_id')[0]
     constraint_name = 'foreign_id_refs_id_%x' % (abs(
         hash((main_table, reference_table))))
     self.assertEquals(constraint_name, constraint)
     references = db._lookup_constraint_references(main_table, constraint)
     self.assertEquals((reference_table, 'id'), references)
     db.delete_table(main_table)
     db.delete_table(reference_table)
Ejemplo n.º 10
0
 def test_constraint_references(self):
     """Tests that referred table is reported accurately"""
     if db.backend_name != "mysql":
         return
     main_table = 'test_cns_ref'
     reference_table = 'test_cr_foreign'
     db.start_transaction()
     self._create_foreign_tables(main_table, reference_table)
     db.execute_deferred_sql()
     constraint = db._find_foreign_constraints(main_table, 'foreign_id')[0]
     constraint_name = 'foreign_id_refs_id_%x' % (abs(hash((main_table,
         reference_table))))
     self.assertEquals(constraint_name, constraint)
     references = db._lookup_constraint_references(main_table, constraint)
     self.assertEquals((reference_table, 'id'), references)
     db.delete_table(main_table)
     db.delete_table(reference_table)
Ejemplo n.º 11
0
 def test_renamed_referenced_table(self):
     """Rename a table referred to in a foreign key"""
     main_table = 'test_rn_refd_table'
     ref_table = 'test_rrt_ref'
     renamed_table = 'test_renamed_ref'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._lookup_reverse_constraint(ref_table)
     self.assertEquals(len(constraints), 1)
     db.rename_table(ref_table, renamed_table)
     db.execute_deferred_sql()  #Create constraints
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     (rtable, rcolumn) = db._lookup_constraint_references(
             main_table, constraints[0])
     self.assertEquals(renamed_table, rtable)
     db.delete_table(main_table)
     db.delete_table(renamed_table)
Ejemplo n.º 12
0
 def test_renamed_referenced_table(self):
     """Rename a table referred to in a foreign key"""
     main_table = 'test_rn_refd_table'
     ref_table = 'test_rrt_ref'
     renamed_table = 'test_renamed_ref'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._lookup_reverse_constraint(ref_table)
     self.assertEquals(len(constraints), 1)
     db.rename_table(ref_table, renamed_table)
     db.execute_deferred_sql()  #Create constraints
     constraints = db._find_foreign_constraints(main_table, 'foreign_id')
     self.assertEquals(len(constraints), 1)
     (rtable, rcolumn) = db._lookup_constraint_references(
             main_table, constraints[0])
     self.assertEquals(renamed_table, rtable)
     db.delete_table(main_table)
     db.delete_table(renamed_table)
Ejemplo n.º 13
0
 def test_rename_fk_inbound(self):
     """
     Tests that the column referred to by an external column can be renamed.
     Edge case, but also useful as stepping stone to renaming tables.
     """
     main_table = 'test_rename_fk_inbound'
     ref_table = 'test_rfi_ref'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._lookup_reverse_constraint(ref_table, 'id')
     self.assertEquals(len(constraints), 1)
     db.rename_column(ref_table, 'id', 'rfi_id')
     db.execute_deferred_sql()  #Create constraints
     constraints = db._lookup_reverse_constraint(ref_table, 'rfi_id')
     self.assertEquals(len(constraints), 1)
     cname = db._find_foreign_constraints(main_table, 'foreign_id')[0]
     (rtable, rcolumn) = db._lookup_constraint_references(main_table, cname)
     self.assertEquals(rcolumn, 'rfi_id')
     db.delete_table(main_table)
     db.delete_table(ref_table)
Ejemplo n.º 14
0
 def test_rename_fk_inbound(self):
     """
     Tests that the column referred to by an external column can be renamed.
     Edge case, but also useful as stepping stone to renaming tables.
     """
     main_table = 'test_rename_fk_inbound'
     ref_table = 'test_rfi_ref'
     self._create_foreign_tables(main_table, ref_table)
     db.execute_deferred_sql()
     constraints = db._lookup_reverse_constraint(ref_table, 'id')
     self.assertEquals(len(constraints), 1)
     db.rename_column(ref_table, 'id', 'rfi_id')
     db.execute_deferred_sql()  #Create constraints
     constraints = db._lookup_reverse_constraint(ref_table, 'rfi_id')
     self.assertEquals(len(constraints), 1)
     cname = db._find_foreign_constraints(main_table, 'foreign_id')[0]
     (rtable, rcolumn) = db._lookup_constraint_references(main_table, cname)
     self.assertEquals(rcolumn, 'rfi_id')
     db.delete_table(main_table)
     db.delete_table(ref_table)