Files
dawarich/db/seeds.rb
Eugene Burmakin cf3b7a116d Fix a few bugs
2025-05-18 19:48:52 +02:00

41 lines
992 B
Ruby

# frozen_string_literal: true
if User.none?
puts 'Creating user...'
email = 'demo@dawarich.app'
User.create!(
email:,
password: 'password',
password_confirmation: 'password',
admin: true,
status: :active,
active_until: 100.years.from_now
)
puts "User created: '#{email}' / password: 'password'"
end
if Country.none?
puts 'Creating countries...'
countries_json = Oj.load(File.read(Rails.root.join('lib/assets/countries.geojson')))
factory = RGeo::Geos.factory(srid: 4326)
countries_multi_polygon = RGeo::GeoJSON.decode(countries_json.to_json, geo_factory: factory)
ActiveRecord::Base.transaction do
countries_multi_polygon.each do |country, index|
p "Creating #{country.properties['name']}..."
Country.create!(
name: country.properties['name'],
iso_a2: country.properties['ISO3166-1-Alpha-2'],
iso_a3: country.properties['ISO3166-1-Alpha-3'],
geom: country.geometry
)
end
end
end