Skip to content

Commit 781a8a7

Browse files
committed
Add unique constraint on moped_components_subcomponents table and comment
1 parent fc56ef6 commit 781a8a7

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

  • moped-database/migrations/1745881623802_decom_and_new_subcomponents

moped-database/migrations/1745881623802_decom_and_new_subcomponents/down.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
-- if we delete the component tag in the future, we will soft delete and leave existing data intact
1+
-- if we delete the added component tag in the future, we will soft delete and leave existing data intact
2+
3+
-- Remove unique constraint to allow for duplicate component/subcomponent associations
4+
ALTER TABLE moped_components_subcomponents
5+
DROP CONSTRAINT unique_component_subcomponents;
26

37
-- Restore previous component tag name
48
UPDATE moped_component_tags SET name = 'Upgrades Existing', type = 'Bikeways - Performance Measure', slug = 'bikeways_performance_measure_upgrades_existing'

moped-database/migrations/1745881623802_decom_and_new_subcomponents/up.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
-- Add unique constraint to ensure no duplicate component/subcomponent associations
2+
ALTER TABLE moped_components_subcomponents
3+
ADD CONSTRAINT unique_component_subcomponents
4+
UNIQUE (component_id, subcomponent_id);
5+
6+
COMMENT ON CONSTRAINT unique_component_subcomponents ON moped_components_subcomponents IS 'Ensures no duplicate component/subcomponent associations';
7+
8+
-- Alter moped_component_tags table to allow null names for new tags and updates to existing tags with empty names
9+
ALTER TABLE moped_component_tags
10+
ALTER COLUMN name DROP NOT NULL;
11+
112
-- Insert new tag to mark decommissioned components
213
INSERT INTO moped_component_tags (name, type, slug) VALUES
314
('', 'Decommissioned / Upgraded Component', 'decommissioned_upgraded_component');

0 commit comments

Comments
 (0)