File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 2525# Map of all integer sequence names to their type tokens
2626sequence_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)
2932sequence_name_to_field_name = {}
3033
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 )
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+
114129for s in statements :
115130 print (s , end = "" )
You can’t perform that action at this time.
0 commit comments