Closed mithi closed 3 years ago
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
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
Currently the foreign key is not readable IE