diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint index 4c8ebbb5..f70752a4 100755 --- a/bin/docker-entrypoint +++ b/bin/docker-entrypoint @@ -16,11 +16,11 @@ if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then # db:prepare - https://www.bigbinary.com/blog/rails-6-adds-rails-db-prepare-to-migrate-or-setup-a-database ./bin/rails db:migrate - echo "####################################################" - echo "docker-entrypoint -> Running rails db:seed" - echo "####################################################" + # echo "####################################################" + # echo "docker-entrypoint -> Running rails db:seed" + # echo "####################################################" # Ensure seeds are run - ./bin/rails db:seed + # ./bin/rails db:seed fi echo "" diff --git a/db/seeds/models/legislator.rb b/db/seeds/models/legislator.rb index 56ff28e0..e3e89d8c 100644 --- a/db/seeds/models/legislator.rb +++ b/db/seeds/models/legislator.rb @@ -28,12 +28,14 @@ def initialize(j, sway_locale) raise "No bioguide id in Legislator json. Cannot seed Legislator." end + d = (j.fetch("district", nil).presence || "0").to_s if Legislator.joins(:district).find_by( + active: true, external_id: bioguide_id, district: { name: SeedLegislator.district_name( RegionUtil.from_region_name_to_region_code(j.fetch("state")), - j.fetch("district", 0) + d&.remove_non_digits&.to_i ) }, party: Legislator.to_party_char_from_name(j.fetch("partyName")) @@ -43,9 +45,6 @@ def initialize(j, sway_locale) return end - Rails.logger.info("Seeding Congressional Legislator #{bioguide_id}") - puts "Seeding Congressional Legislator #{bioguide_id}" - response = Faraday.get("https://api.congress.gov/v3/member/#{bioguide_id}?&api_key=#{api_key}") @j = JSON.parse(response.body)["member"] if @j.nil? @@ -77,7 +76,7 @@ def self.read_legislators(sway_locale) sig { params(region_code: String, district: Integer).returns(String) } def self.district_name(region_code, district) - (district.is_a?(Integer) || district.is_numeric?) ? "#{region_code}#{district}" : district + "#{region_code}#{district}" end sig { returns(Legislator) } @@ -87,6 +86,9 @@ def seed sig { returns(Legislator) } def legislator + Rails.logger.info("Seeding #{sway_locale.city.titleize} Legislator #{external_id}") + puts "Seeding #{sway_locale.city.titleize} Legislator #{external_id}" + l = Legislator.find_or_initialize_by( external_id:, first_name:, @@ -121,8 +123,8 @@ def district raise NonStateRegionCode.new("regionCode must be a US state (until Sway goes international :) - Received #{region_code}") end - d = j.fetch("district", nil).presence || 0 - name = SeedLegislator.district_name(region_code, d&.to_i) + d = (j.fetch("district", nil).presence || "0").to_s + name = SeedLegislator.district_name(region_code, d&.remove_non_digits&.to_i) District.find_or_create_by!( name:,