Skip to content

Commit

Permalink
Schema-qualify table when dropping columns. Fixes #26.
Browse files Browse the repository at this point in the history
 * pyrseas/dbobject/column.py (Column.drop): Add schema qualification.
 * tests/dbobject/test_column.py: New regression test.
  • Loading branch information
jmafc committed Mar 16, 2012
1 parent 358e95d commit fa4e0fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pyrseas/dbobject/column.py
Expand Up @@ -57,10 +57,13 @@ def drop(self):
if hasattr(self, 'dropped'):
return ""
if hasattr(self, '_table'):
(contype, objtype) = (self._table.objtype, 'COLUMN')
(comptype, objtype) = (self._table.objtype, 'COLUMN')
compname = self._table.qualname()
else:
(contype, objtype) = ('TYPE', 'ATTRIBUTE')
return "ALTER %s %s DROP %s %s" % (contype, self.table, objtype,
# TODO: this is only a PG 9.1 feature, so more is required
(comptype, objtype) = ('TYPE', 'ATTRIBUTE')
compname = self.table
return "ALTER %s %s DROP %s %s" % (comptype, compname, objtype,
self.name)

def rename(self, newname):
Expand Down
12 changes: 12 additions & 0 deletions tests/dbobject/test_column.py
Expand Up @@ -177,6 +177,18 @@ def test_drop_add_column3(self):
"ALTER TABLE t1 ADD COLUMN c4 text")
self.assertEqual(dbsql[2], "ALTER TABLE t1 DROP COLUMN c1")

def test_drop_column_in_schema(self):
"Drop a column from a table in a non-public schema"
self.db.execute("CREATE SCHEMA s1")
self.db.execute_commit("CREATE TABLE s1.t1 (c1 integer, c2 text, "
"c3 date)")
inmap = self.std_map()
inmap.update({'schema s1': {'table t1': {
'columns': [{'c1': {'type': 'integer'}},
{'c2': {'type': 'text'}}]}}})
dbsql = self.db.process_map(inmap)
self.assertEqual(fix_indent(dbsql[0]),
"ALTER TABLE s1.t1 DROP COLUMN c3")

def suite():
tests = unittest.TestLoader().loadTestsFromTestCase(ColumnToSqlTestCase)
Expand Down

0 comments on commit fa4e0fa

Please sign in to comment.