Open brindakv opened 3 years ago
@brindakv I have added in the 2021_01_model_updates.py
script the function drop_table(model, schema_name, table_name)
which drops the table together with the referenced keys.
Example of call:
drop_table(model, 'PDB', 'ihm_pseudo_site')
FYI, hereby is way my script was renaming the composite FK:
if 'structure_id' in foreign_key_columns:
if 'RID' in referenced_columns:
use the combo2
else:
use the combo1
else:
use denorm if length > 63
@svoinea In the drop_table
function, what happens if the child table that references the foreign key has data? Can the foreign key be dropped?
@brindakv Dropping a FK does not drop its columns. It drops only the condition
the columns data have to meet. Therefore the data is preserved.
Current algorithm used for renaming the composite FK:
if 'RID' in referenced_columns:
if 'structure_id' in foreign_key_columns:
use combo1
else:
use combo2
else:
if length > 63:
use denorm
Current results:
PK to be renamed:
pk_rename.txt
FK to be renamed with combo1
:
fk_rename_to_combo1.txt
FK to be renamed with combo2
:
fk_rename_to_combo2.txt
FK with structure_id
to be renamed:
fk_rename_structure_id.txt
FK to be renamed with denorm
:
fk_rename_denorm.txt
FK to be renamed:
fk_rename.txt
FK duplicates:
fk_rename_duplicates.txt
FK too long names:
fk_rename_too_long_names.txt
Current PK grouped by the number of columns and the presence of the RID
and/or structure_id
columns
pk.txt
Current FK grouped by the number of columns and the presence of the RID
and/or structure_id
columns
fk.txt
No change was done in the DB.
No suggestions for renaming any PK and or FK.
The two files are just an image of the current keys and foreign keys of the PDB
schema of catalog 99
.
I have identified the following sequence of operations to be done (updating the annotations
and acls
is not included):
32
columns to be renamed and 102
columns to be added (of the form <Parent_Table>_RID
):
columns.txt
102
SQL update statements to load values for the new added <Parent_Table>_RID
columns:
sql.txt
13
Primary Keys to be renamed and 29
Primary Keys to be added:
primary_key.txt
54
Foreign Keys to be renamed, 147
Foreign Keys to be added, and 147
Foreign Keys to be dropped:
foreign_key.txt
I have also identified 13
duplicates in naming the Foreign Keys:
duplicates.txt
and 39
Foreign Keys that have names longer than 63
characters:
long_names.txt
Foreign keys *_fk
relative to the *_fkey
ones:
fk_fkey.txt
Foreign keys used in the annotations: fk_annotations.txt
Foreign keys used in the acl bindings: fk_acl_bindings.txt
ihm_
or changegeometry
togeom
or changetransform
toxform
. 4.1 Create a look up table to change long mmCIF names to shorter Deriva names. Note: Tables with long names are in #42.