Skip to content

Commit 576a5e0

Browse files
committed
add missing file
1 parent f5d856e commit 576a5e0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- This script fix a circular dependency between the gtfsdataset and feed tables
2+
3+
-- 1. Add the new column to gtfsfeed (if not already added)
4+
ALTER TABLE gtfsfeed
5+
ADD COLUMN IF NOT EXISTS geolocation_file_dataset_id VARCHAR(255);
6+
7+
-- 2. Copy existing values from feed to gtfsfeed
8+
-- (we assume gtfsfeed.id = feed.id, since gtfsfeed is a subtype of feed)
9+
UPDATE gtfsfeed gf
10+
SET geolocation_file_dataset_id = f.geolocation_file_dataset_id
11+
FROM feed f
12+
WHERE gf.id = f.id
13+
AND f.geolocation_file_dataset_id IS NOT NULL;
14+
15+
-- 3. Add the foreign key constraint on gtfsfeed
16+
ALTER TABLE gtfsfeed
17+
ADD CONSTRAINT fk_gtfsfeed_geolocation_file_dataset
18+
FOREIGN KEY (geolocation_file_dataset_id) REFERENCES gtfsdataset(id)
19+
ON DELETE SET NULL;
20+
21+
-- 4. Drop the old constraint and column from feed
22+
ALTER TABLE feed DROP CONSTRAINT IF EXISTS fk_feed_geolocation_file_dataset;
23+
ALTER TABLE feed DROP COLUMN IF EXISTS geolocation_file_dataset_id;

0 commit comments

Comments
 (0)