File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 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;
You can’t perform that action at this time.
0 commit comments