Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Change constraint names to more meaningful names #84

Closed
mithi opened this issue Nov 3, 2020 · 3 comments · Fixed by #85
Closed

Change constraint names to more meaningful names #84

mithi opened this issue Nov 3, 2020 · 3 comments · Fixed by #85

Comments

@mithi
Copy link
Owner

mithi commented Nov 3, 2020

Currently the foreign key is not readable IE

        constraint_name         |   table_name   | column_name | foreign_table_name | foreign_column_name 
--------------------------------+----------------+-------------+--------------------+---------------------
 PK_8c82d7f526340ab734260ea46be | migrations     | id          | migrations         | id
 PK_a9fe6ef57784aff6b73159e9b4d | main_stats     | id          | main_stats         | id
 REL_38a6e0a47022a1c957b9018646 | main_stats     | towerId     | main_stats         | towerId
 PK_06005d4dc8ba963484acae34726 | barracks_stats | id          | barracks_stats     | id
 REL_d5dcdad1a2b257a2445db6106f | barracks_stats | towerId     | barracks_stats     | towerId
 PK_e7cb32239cb7dfd5eebae4d0eaf | attack_stats   | id          | attack_stats       | id
 REL_a183facc6b66a4851553798f60 | attack_stats   | towerId     | attack_stats       | towerId
 PK_d35a4e5481305c4848b560a3354 | Towers         | id          | Towers             | id
 unique_tower                   | Towers         | name        | Towers             | kingdom
 unique_tower                   | Towers         | name        | Towers             | name
 unique_tower                   | Towers         | kingdom     | Towers             | kingdom
 unique_tower                   | Towers         | kingdom     | Towers             | name
 FK_38a6e0a47022a1c957b90186462 | main_stats     | towerId     | Towers             | id
 FK_d5dcdad1a2b257a2445db6106fb | barracks_stats | towerId     | Towers             | id
 FK_a183facc6b66a4851553798f608 | attack_stats   | towerId     | Towers             | id
 PK_433b7560ea75956d78120228a2c | ability_level  | id          | ability_level      | id
 PK_5643559d435d01ec126981417a2 | ability        | id          | ability            | id
 FK_0d9185e58cdacbdb7787c410d62 | ability_level  | abilityId   | ability            | id
 FK_b8d8816b111ff43dc4f8a9f6afe | ability        | towerId     | Towers             | id
 PK_11cbd4cf88c203da6f6e0c22dbe | build_sequence | id          | build_sequence     | id
 REL_c598f4f8ace2c65225b034987f | build_sequence | level4Id    | build_sequence     | level4Id
 FK_a0485cb10760fbbe70d7bfea439 | build_sequence | level1Id    | Towers             | id
 FK_e7720dd1227b31428bdd710bac9 | build_sequence | level2Id    | Towers             | id
 FK_fbdaaafa5aaf958509352c74637 | build_sequence | level3Id    | Towers             | id
 FK_c598f4f8ace2c65225b034987f3 | build_sequence | level4Id    | Towers             | id
(25 rows)
@mithi
Copy link
Owner Author

mithi commented Nov 3, 2020

List all constraints on database

SELECT
    tc.constraint_name, tc.table_name, kcu.column_name, 
    ccu.table_name AS foreign_table_name,
    ccu.column_name AS foreign_column_name 
FROM 
    information_schema.table_constraints AS tc 
    JOIN information_schema.key_column_usage AS kcu
      ON tc.constraint_name = kcu.constraint_name
    JOIN information_schema.constraint_column_usage AS ccu
      ON ccu.constraint_name = tc.constraint_name

@mithi
Copy link
Owner Author

mithi commented Nov 3, 2020

After migration this is the end result

            constraint_name             |   table_name   | column_name | foreign_table_name | foreign_column_name 
----------------------------------------+----------------+-------------+--------------------+---------------------
 unique_tower                           | Towers         | name        | Towers             | kingdom
 unique_tower                           | Towers         | name        | Towers             | name
 unique_tower                           | Towers         | kingdom     | Towers             | kingdom
 unique_tower                           | Towers         | kingdom     | Towers             | name
 UNIQUE_main_stats_towerId              | main_stats     | towerId     | main_stats         | towerId
 UNIQUE_barracks_stats_towerId          | barracks_stats | towerId     | barracks_stats     | towerId
 UNIQUE_attack_stats_towerId            | attack_stats   | towerId     | attack_stats       | towerId
 UNIQUE_build_sequence_level4Id         | build_sequence | level4Id    | build_sequence     | level4Id
 PK_migrations_id                       | migrations     | id          | migrations         | id
 PK_main_stats_id                       | main_stats     | id          | main_stats         | id
 PK_barracks_stats_id                   | barracks_stats | id          | barracks_stats     | id
 PK_attack_stats_id                     | attack_stats   | id          | attack_stats       | id
 PK_Towers_id                           | Towers         | id          | Towers             | id
 PK_ability_level_id                    | ability_level  | id          | ability_level      | id
 PK_ability_id                          | ability        | id          | ability            | id
 PK_build_sequence_id                   | build_sequence | id          | build_sequence     | id
 FK_main_stats_towerId__Towers_id       | main_stats     | towerId     | Towers             | id
 FK_barracks_stats_towerId__Towers_id   | barracks_stats | towerId     | Towers             | id
 FK_attack_stats_towerId__Towers_id     | attack_stats   | towerId     | Towers             | id
 FK_ability_level_abilityId__ability_id | ability_level  | abilityId   | ability            | id
 FK_ability_towerId__Towers_id          | ability        | towerId     | Towers             | id
 FK_build_sequence_level1Id__Towers_id  | build_sequence | level1Id    | Towers             | id
 FK_build_sequence_level2Id__Towers_id  | build_sequence | level2Id    | Towers             | id
 FK_build_sequence_level3Id__Towers_id  | build_sequence | level3Id    | Towers             | id
 FK_build_sequence_level4Id__Towers_id  | build_sequence | level4Id    | Towers             | id
SELECT * FROM information_schema.check_constraints;

 constraint_catalog | constraint_schema |    constraint_name     |        check_clause         
--------------------+-------------------+------------------------+-----------------------------
 kingdom_rush_db    | public            | 2200_184523_1_not_null | id IS NOT NULL
 kingdom_rush_db    | public            | 2200_184533_7_not_null | towerType IS NOT NULL
 kingdom_rush_db    | public            | 2200_184523_3_not_null | range IS NOT NULL
 kingdom_rush_db    | public            | 2200_184569_1_not_null | id IS NOT NULL
 kingdom_rush_db    | public            | 2200_184503_4_not_null | buildCost IS NOT NULL
 kingdom_rush_db    | public            | 2200_184462_3_not_null | name IS NOT NULL
 kingdom_rush_db    | public            | 2200_184462_2_not_null | timestamp IS NOT NULL
 kingdom_rush_db    | public            | 2200_184569_2_not_null | name IS NOT NULL
 kingdom_rush_db    | public            | 2200_184561_3_not_null | cost IS NOT NULL
 kingdom_rush_db    | public            | 2200_184533_4_not_null | level IS NOT NULL
 kingdom_rush_db    | public            | 2200_184513_2_not_null | numberOfUnits IS NOT NULL
 kingdom_rush_db    | public            | 2200_184569_3_not_null | description IS NOT NULL
 kingdom_rush_db    | public            | 2200_184561_2_not_null | level IS NOT NULL
 kingdom_rush_db    | public            | 2200_184561_1_not_null | id IS NOT NULL
 kingdom_rush_db    | public            | 2200_184533_1_not_null | id IS NOT NULL
 kingdom_rush_db    | public            | 2200_184513_1_not_null | id IS NOT NULL
 kingdom_rush_db    | public            | 2200_184513_4_not_null | health IS NOT NULL
 kingdom_rush_db    | public            | 2200_184513_6_not_null | towerId IS NOT NULL
 kingdom_rush_db    | public            | 2200_184503_5_not_null | towerId IS NOT NULL
 kingdom_rush_db    | public            | 2200_184533_2_not_null | name IS NOT NULL
 kingdom_rush_db    | public            | 2200_184533_5_not_null | kingdom IS NOT NULL
 kingdom_rush_db    | public            | 2200_184462_1_not_null | id IS NOT NULL
 kingdom_rush_db    | public            | 2200_184523_4_not_null | towerId IS NOT NULL
 kingdom_rush_db    | public            | 2200_184590_1_not_null | id IS NOT NULL
 kingdom_rush_db    | public            | 2200_184569_4_not_null | towerId IS NOT NULL
 kingdom_rush_db    | public            | 2200_184561_4_not_null | abilityId IS NOT NULL
 kingdom_rush_db    | public            | 2200_184523_2_not_null | fireInterval IS NOT NULL
 kingdom_rush_db    | public            | 2200_184513_5_not_null | armor IS NOT NULL
 kingdom_rush_db    | public            | 2200_184503_1_not_null | id IS NOT NULL
 kingdom_rush_db    | public            | 2200_184503_3_not_null | damageMaximum IS NOT NULL
 kingdom_rush_db    | public            | 2200_184503_2_not_null | damageMinimum IS NOT NULL

@mithi mithi changed the title Change foreign key names to more meaningful names Change constraint names to more meaningful names Nov 3, 2020
mithi added a commit that referenced this issue Nov 3, 2020
Change constraint names to more meaningful names 
For more information see :
#84

Fix: setup script (install first before anything else)
Improve logging when seeding database tables
@mithi mithi linked a pull request Nov 3, 2020 that will close this issue
@mithi mithi closed this as completed Nov 3, 2020
@mithi
Copy link
Owner Author

mithi commented Nov 4, 2020

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant