Skip to content

Commit

Permalink
remove seeds from every deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
dcordz committed Jan 5, 2025
1 parent 9312715 commit cfb65f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions bin/docker-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
16 changes: 9 additions & 7 deletions db/seeds/models/legislator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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?
Expand Down Expand Up @@ -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) }
Expand All @@ -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:,
Expand Down Expand Up @@ -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:,
Expand Down

0 comments on commit cfb65f2

Please sign in to comment.