Import and rake tasks
This app uses a set of Rake tasks to import datasets and perform routine maintenance. Below is a concise reference for the most common tasks and how to run them locally and in CI/CD.
Quick start
- Ensure dependencies are installed and the app can boot.
 - Seed or migrate the database as needed.
 - Run the full import (safe, non-destructive for dictionary tables):
 
bundle exec rake db:import
To reimport everything from scratch (destructive for several tables) use:
bundle exec rake db:reimport
Global import tasks
db:import— Imports all datasets in the correct order and replaces non-dictionary data. It invokes, in order:locations:importlocation_members:importndcs:full:importndcs:full:indexsdgs:importndc_sdg_targets:importindc:importhistorical_emissions:importadaptation:importwri_metadata:importwb_extra:importtimeline:importquantifications:importsocioeconomics:importstories:importkey_visualizations:importcountry_profile:importzip_files:import
db:reimport— Fully resets a number of tables and then runsdb:import. It deletes:NdcSdg::Target,NdcSdg::Goal,HistoricalEmissions::Record,WbExtra::CountryData,Socioeconomic::Indicator, allLocations, and allStoryrecords before importing again. Use with caution.
Dataset-specific tasks
- Locations 
locations:import— Import locations from CSV.location_members:import— Import location members from CSV.
 - NDCs (full text) 
ndcs:full:import— Store and index NDC full text from S3.ndcs:full:index— Rebuild the full-text TSV index.
 - SDGs and NDC-SDG 
sdgs:import— Import SDG data from CSV.ndc_sdg_targets:import— Part of the overall import sequence (defined in codebase alongside SDGs/INDC models).
 - INDC 
indc:import— Import INDC dataset from CSV sources.indc:subsectors_data— Generate NDC Explorer subsectors data.indc:delete_subsectors_data— Clear auto-generated subsector indicators and values.
 - Historical emissions 
historical_emissions:import— Import historical emissions from CSV.
 - Adaptation 
adaptation:import— Import Adaptation dataset from CSV.
 - WRI metadata 
wri_metadata:import— Import WRI metadata from CSV.
 - World Bank extras 
wb_extra:import— Import WB Extra dataset from CSV.
 - Timeline 
timeline:import— Import documents timeline from CSV.
 - Quantifications 
quantifications:import— Import Quantifications dataset from CSV.
 - Socioeconomics 
socioeconomics:import— Import Socioeconomics dataset from CSV.
 - Stories 
stories:import— Import latest stories from WRI RSS feed.stories:fresh_import— Delete existing stories and re-import.
 - Key visualizations 
key_visualizations:import— Import Key Visualizations definitions/data.
 - Country profile 
country_profile:import— Import Country Profile data.
 - Zip files 
zip_files:import— Create or refresh the Zip files structure (no upload).zip_files:import_with_upload— Generate and upload Zip files.
 - Agriculture profile 
agriculture_profile:import— Run all agriculture subtasks (metadata, emissions, contexts, profile).agriculture_profile:import_metadataagriculture_profile:import_emissionsagriculture_profile:import_contextsagriculture_profile:import_profile
 
Database utilities
db:import_maxmind— Download the GeoLite2 Country database and place it atdb/GeoLite2-Country.mmdb. RequiresMAXMIND_LICENSE_KEYin environment. Example:
MAXMIND_LICENSE_KEY=your_key bundle exec rake db:import_maxmind
-  
db:user_creation— Create a default user usingDEV_USER_IDfrom.env. -  
db:mark_countries_with_in_eu_flag— Mark EU member countries inlocationsusing the internal EU list. 
MaxMind geolocation
MaxMind’s GeoLite2 Country database is used to resolve a user’s IP address to a 2-letter ISO country code. This enables country-aware behavior (e.g., default country selection) via a fast, local lookup.
- Implementation: see 
app/services/geolocation_service.rb(uses themaxmind-dbgem). - DB selection: 
- Dev/Test: uses 
db/GeoLite2-Country-Test.mmdbby default. - Real DB: uses 
db/GeoLite2-Country.mmdbwhenMAXMIND_REAL_DBis set or in non-dev/test environments. 
 - Dev/Test: uses 
 - Overrides and fallbacks: 
- In development, set 
CW_USER_COUNTRY_OVERRIDE(e.g.,US) to bypass lookup. - If an IP isn’t found, the service returns 
nil. 
 - In development, set 
 - Setup: run 
db:import_maxmindto download the real DB. RequiresMAXMIND_LICENSE_KEY. 
Examples:
# Download the real GeoLite2 Country DB
MAXMIND_LICENSE_KEY=your_key bundle exec rake db:import_maxmind
# Force using the real DB in dev
MAXMIND_REAL_DB=1 bundle exec rails s
# Override country in development (no lookup)
CW_USER_COUNTRY_OVERRIDE=GB bundle exec rails s
Running tasks
- Local: 
- Ensure 
.envhas required keys (see_docs/env.md). - Use 
bundle exec rake <task>; addRAILS_ENV=development|testas needed. 
 - Ensure 
 - Deployment/CI: 
- Common tasks include 
db:migrate,db:import_maxmind,assets:precompile, anddb:admin_boilerplate:create(see Capistrano logs and deploy scripts). 
 - Common tasks include 
 
Notes and tips
- Long-running imports log with 
TimedLogger; check your console output or logs for progress. - When iterating on a single dataset, prefer the dataset-specific import task instead of the full 
db:importto save time. db:reimportis destructive; ensure you understand the reset it performs before running it against shared databases.