11import re
2+ import uuid
23
34import pyodbc # adapter for SQL Server
45import psycopg2 # adapter for PostgreSQL
@@ -50,6 +51,14 @@ def get_settings_from_file():
5051 exit (1 )
5152
5253
54+ def is_uuid (value ):
55+ try :
56+ uuid .UUID (value , version = 4 )
57+ return True
58+ except ValueError :
59+ return False
60+
61+
5362# tries to connect to both databases
5463def connect ():
5564 print ("Setting up connection to the databases:" )
@@ -134,6 +143,9 @@ def generate_insertion_string(row):
134143 for x in row :
135144 # Strings must be enclosed in apostrophes, also escape singe quotes in a string by doubling them
136145 if isinstance (x , str ):
146+ # The .NET webapp used to create uppercase UUIDs, so we try to detect it and lowercase it
147+ if 32 <= len (x ) <= 36 and is_uuid (x ):
148+ x = x .lower ()
137149 row_list .append ("'" + str (x ).replace ("'" , "''" ) + "'" )
138150 # Dates and datetimes must be enclosed in apostrophes
139151 elif isinstance (x , datetime .datetime ) or isinstance (x , datetime .date ):
@@ -225,6 +237,9 @@ def migrate():
225237 "\" FeedbackUUID\" , \" AuditUserID\" ) VALUES ('2000 01 01 00:00:00.000000', 0, 0, 0);" )
226238
227239 # Set up all the columns we're going to migrate.
240+ cursor = old_cursor .execute ("SELECT TOP 1 * FROM " + table + ";" )
241+ old_columns_with_types = {column [0 ].lower (): column [1 ] for column in cursor .description }
242+
228243 new_cursor .execute ("SELECT COLUMN_NAME, COLUMN_DEFAULT "
229244 "FROM information_schema.COLUMNS WHERE TABLE_NAME = '" + table + "';" )
230245 rows = new_cursor .fetchall ()
@@ -238,7 +253,7 @@ def migrate():
238253 old_cols_list = []
239254 new_cols_list = []
240255 for row in rows :
241- if row [0 ] not in EXCLUDED_COLUMNS :
256+ if row [0 ] not in EXCLUDED_COLUMNS and row [ 0 ]. lower () in old_columns_with_types :
242257 col_default = extract_sequence_name (row [1 ])
243258 if col_default :
244259 sequence_columns [row [0 ]] = col_default
0 commit comments