From 7f96fc68dab9b73ed44d13a1363d68854a3beed8 Mon Sep 17 00:00:00 2001 From: Michaela Ockova Date: Sat, 25 Jan 2020 16:32:49 +0100 Subject: [PATCH 1/2] Fix unique constraint error --- gtfspy/import_loaders/stop_times_loader.py | 2 +- gtfspy/import_loaders/table_loader.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gtfspy/import_loaders/stop_times_loader.py b/gtfspy/import_loaders/stop_times_loader.py index 59e1a52..ac7a76d 100644 --- a/gtfspy/import_loaders/stop_times_loader.py +++ b/gtfspy/import_loaders/stop_times_loader.py @@ -57,7 +57,7 @@ def index(cls, cur): # This is used for the stop frequencies analysis. #cur.execute('CREATE INDEX idx_stop_times_tid_ath_sid ON stop_times (trip_I, arr_time_hour, stop_id)') # ^-- much slower than the next index. - cur.execute('CREATE INDEX idx_stop_times_ath_tid_sid ON stop_times (arr_time_hour, trip_I, stop_I)') + cur.execute('CREATE INDEX IF NOT EXISTS idx_stop_times_ath_tid_sid ON stop_times (arr_time_hour, trip_I, stop_I)') # This has now been moved to DayTripsMaterializer, but is left # here in case we someday want to make DayTripsMaterializer diff --git a/gtfspy/import_loaders/table_loader.py b/gtfspy/import_loaders/table_loader.py index b09ef1e..d181c88 100644 --- a/gtfspy/import_loaders/table_loader.py +++ b/gtfspy/import_loaders/table_loader.py @@ -279,7 +279,7 @@ def insert_data(self, conn): # proceed. Since there is nothing to import, just continue the loop print("Not importing %s into %s for %s" % (self.fname, self.table, prefix)) continue - stmt = '''INSERT INTO %s (%s) VALUES (%s)''' % ( + stmt = '''INSERT OR REPLACE INTO %s (%s) VALUES (%s)''' % ( self.table, (', '.join([x for x in fields if x[0] != '_'] + self.extra_keys)), (', '.join([":" + x for x in fields if x[0] != '_'] + self.extra_values)) From 17752dc4638a26ce31982201120018d6214782d7 Mon Sep 17 00:00:00 2001 From: Richard Darst Date: Wed, 11 Mar 2020 15:48:36 +0200 Subject: [PATCH 2/2] CHANGELOG.md: add note about updating existing databases --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a01004..d431a77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,3 +3,13 @@ - Update to be compatible with networkx 2.0. There should be no changes needed with networkx 1.11 (it should still work), but bugs are possible. Please report. Github #34 + +- Allow one to incrementally update databases with new GTFS files: + `INSERT OR REPLACE` into existing databases (and don't create + indexes if they already exist). It is possible that there are + subtle bugs here - check carefully and report back. #27, thanks to + @evelyn9191 for the change. + + + +