Skip to content

Commit

Permalink
Import improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenyeargin committed Jul 14, 2024
1 parent 78bb6cc commit e887ddc
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 83 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ gem 'gtfs'
gem 'gtfs-realtime-bindings'

# Handle bulk inserts
gem 'activerecord-import'
gem 'bulk_insert', '~> 1.9'

# Paginate API results
Expand Down
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ GEM
activerecord (7.0.8.4)
activemodel (= 7.0.8.4)
activesupport (= 7.0.8.4)
activerecord-import (1.7.0)
activerecord (>= 4.2)
activestorage (7.0.8.4)
actionpack (= 7.0.8.4)
activejob (= 7.0.8.4)
Expand Down Expand Up @@ -241,6 +243,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
activerecord-import
bootsnap
bulk_insert (~> 1.9)
debug
Expand All @@ -263,4 +266,4 @@ RUBY VERSION
ruby 3.0.3p157

BUNDLED WITH
2.4.22
2.4.12
6 changes: 6 additions & 0 deletions db/migrate/20240714184344_add_index_to_stop_times.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddIndexToStopTimes < ActiveRecord::Migration[7.0]
def change
add_index :stop_times, :trip_id
add_index :stop_times, :trip_gid
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 103 additions & 0 deletions lib/tasks/clean.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# frozen_string_literal: true

namespace :clean do
task default: 'clean:all'

desc 'Truncates existing tables'
task all: :environment do |t|
puts "Running #{t}"
Rake::Task['clean:agency'].invoke
Rake::Task['clean:calendar_dates'].invoke
Rake::Task['clean:calendars'].invoke
Rake::Task['clean:fare_attributes'].invoke
Rake::Task['clean:fare_rules'].invoke
Rake::Task['clean:feed_info'].invoke
Rake::Task['clean:frequencies'].invoke
Rake::Task['clean:routes'].invoke
Rake::Task['clean:shapes'].invoke
Rake::Task['clean:stop_times'].invoke
Rake::Task['clean:stops'].invoke
Rake::Task['clean:transfers'].invoke
Rake::Task['clean:trips'].invoke
puts "Finished #{t}"
end

desc 'Truncate agency'
task agency: :environment do |t|
puts "Running #{t}"

Agency.delete_all
end

desc 'Truncate stops'
task stops: :environment do |t|
puts "Running #{t}"
Stop.delete_all
end

desc 'Truncate routes'
task routes: :environment do |t|
puts "Running #{t}"
Route.delete_all
end

desc 'Truncate calendar'
task calendars: :environment do |t|
puts "Running #{t}"
Calendar.delete_all
end

desc 'Truncate calendar_dates'
task calendar_dates: :environment do |t|
puts "Running #{t}"
CalendarDate.delete_all
end

desc 'Truncate shapes'
task shapes: :environment do |t|
puts "Running #{t}"
Shape.delete_all
end

desc 'Truncate trips'
task trips: :environment do |t|
puts "Running #{t}"
Trip.delete_all
end

desc 'Truncate stop_times'
task stop_times: :environment do |t|
puts "Running #{t}"
StopTime.delete_all
end

desc 'Truncate fare_attributes'
task fare_attributes: :environment do |t|
puts "Running #{t}"
FareAttribute.delete_all
end

desc 'Truncate fare_rules'
task fare_rules: :environment do |t|
puts "Running #{t}"
FareRule.delete_all
end

desc 'Truncate frequencies'
task frequencies: :environment do |t|
puts "Running #{t}"
Frequency.delete_all
end

desc 'Truncate transfers'
task transfers: :environment do |t|
puts "Running #{t}"
Transfer.delete_all
end

desc 'Truncate feed_info'
task feed_info: :environment do |t|
puts "Running #{t}"
FeedInfo.delete_all
end
end
Loading

0 comments on commit e887ddc

Please sign in to comment.