bdit_data-sources
bdit_data-sources copied to clipboard
GCC Puller: Create primary key only if not exist
Ran into an error
ERROR: multiple primary keys for table "loop_detector" are not allowed
Not exactly sure why this wasn't an issue before....
And because there is no add constraint if exist
, there are a couple of solutions:
- drop primary key and create again (NO CANNOT DO, BECAUSE IT WILL MESS WITH OUR AUDIT TABLE STRUCTURE)
- Look at information table and see if a primary key exist on the table
- Edit the create table line to do something like
Create table if not exist (
column1 data_type,
column2 data_type,
constraint pk_mail_app_recipients primary key (column1)
Then it will only add a primary key constraint when a new table is created.
https://github.com/CityofToronto/bdit_data-sources/blob/f79fd6eee455f2ca35a002ba081270f8f13012c1/gis/gccview/gcc_puller_functions.py#L191
@chmnata should this issue also be closed as not planned?