Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Add double quotes around foreign key referenced columns #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions mysql2pgsql/lib/postgres_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,21 @@ def get_type(column):
if column.get('auto_increment', None):
return '%s DEFAULT nextval(\'"%s_%s_seq"\'::regclass) NOT NULL' % (
column_type, column['table_name'], column['name'])

return '%s%s%s' % (column_type, (default if not default == None else ''), null)

def table_comments(self, table):
comments = StringIO()
if table.comment:
if table.comment:
comments.write(self.table_comment(table.name, table.comment))
for column in table.columns:
comments.write(self.column_comment(table.name, column))
return comments.getvalue()
return comments.getvalue()

def column_comment(self, tablename, column):
if column['comment']:
if column['comment']:
return (' COMMENT ON COLUMN %s.%s is %s;' % ( tablename, column['name'], QuotedString(column['comment']).getquoted()))
else:
else:
return ''

def table_comment(self, tablename, comment):
Expand Down Expand Up @@ -249,7 +249,7 @@ def write_indexes(self, table):
if primary_index:
index_sql.append('ALTER TABLE "%(table_name)s" ADD CONSTRAINT "%(index_name)s_pkey" PRIMARY KEY(%(column_names)s);' % {
'table_name': table.name,
'index_name': '%s%s_%s' % (index_prefix, table.name,
'index_name': '%s%s_%s' % (index_prefix, table.name,
'_'.join(primary_index[0]['columns'])),
'column_names': ', '.join('"%s"' % col for col in primary_index[0]['columns']),
})
Expand All @@ -272,7 +272,7 @@ def write_constraints(self, table):
constraint_sql = []
for key in table.foreign_keys:
constraint_sql.append("""ALTER TABLE "%(table_name)s" ADD FOREIGN KEY ("%(column_name)s")
REFERENCES "%(ref_table_name)s"(%(ref_column_name)s);""" % {
REFERENCES "%(ref_table_name)s"("%(ref_column_name)s");""" % {
'table_name': table.name,
'column_name': key['column'],
'ref_table_name': key['ref_table'],
Expand Down