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

Fixing case sensitive fk #88

Open
wants to merge 1 commit into
base: develop
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
5 changes: 2 additions & 3 deletions mysql2pgsql/lib/postgres_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def write_indexes(self, table):
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' % (table.name, '_'.join(re.sub('[\W]+', '', c) for c in primary_index[0]['columns'])),
'column_names': ', '.join('%s' % col for col in primary_index[0]['columns']),
'column_names': ', '.join('"%s"' % col for col in primary_index[0]['columns']),
})
for index in table.indexes:
if 'primary' in index:
Expand All @@ -209,14 +209,13 @@ def write_indexes(self, table):
'table_name': table.name,
'column_names': ', '.join('"%s"' % col for col in index['columns']),
})

return index_sql

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