Skip to content

Commit 8a0e8bd

Browse files
committed
Fix handling of incorrect sequences
1 parent 760be4b commit 8a0e8bd

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

convert.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
# Map of all integer sequence names to their type tokens
2626
sequence_name_to_type_token = {}
2727

28+
# List of all bigint sequences
29+
bigint_sequences = []
30+
2831
# Map of all sequence names to the (table, field) tuple they are used by (assumes only one field uses them)
2932
sequence_name_to_field_name = {}
3033

@@ -61,9 +64,10 @@
6164
if tk.ttype == T.Whitespace:
6265
break
6366
seq_name += str(tk)
64-
6567
if str(seq_name_token.tokens[-1]) == 'integer':
6668
sequence_name_to_type_token[seq_name.strip()] = seq_name_token.tokens[-1]
69+
elif str(seq_name_token.tokens[-1]) == seq_name.split(".")[-1]:
70+
bigint_sequences.append(seq_name.strip())
6771

6872
elif str(verb) == 'ALTER':
6973
idx, verb_type = s.token_next(idx, True, True)
@@ -111,5 +115,16 @@
111115
if tgt == field:
112116
field_name_to_type_token[src].value = 'bigint'
113117

118+
for seq_name in bigint_sequences:
119+
field = sequence_name_to_field_name[seq_name]
120+
121+
if field in field_name_to_type_token and field_name_to_type_token[field].value == 'integer':
122+
field_name_to_type_token[field].value = 'bigint'
123+
124+
# Change all foreign keys pointing to that sequence to bigint
125+
for src, tgt in foreign_key_to_target.items():
126+
if tgt == field:
127+
field_name_to_type_token[src].value = 'bigint'
128+
114129
for s in statements:
115130
print(s, end="")

0 commit comments

Comments
 (0)