To upload the 2020 Election data, you need to create a migration. The data source is available here.
// src/migrations/xxxxxxx-upload-election-data-2020.ts
import { MigrationInterface, QueryRunner } from 'typeorm';
export class uploadElectionData2020xxxxxxx implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// Make sure the CSV files are accessible by the PostgreSQL server
await queryRunner.query(`
COPY states (id, name, electoral_votes, boundary) FROM '<path_to_csv_files>/states.csv' WITH (FORMAT csv, HEADER true);
COPY counties (id, name, state_id, boundary) FROM '<path_to_csv_files>/counties.csv' WITH (FORMAT csv, HEADER true);
COPY cities (id, name, state_id, county_id, boundary) FROM '<path_to_csv_files>/cities.csv' WITH (FORMAT csv, HEADER true);
COPY parties (id, name) FROM '<path_to_csv_files>/parties.csv' WITH (FORMAT csv, HEADER true);
COPY candidates (id, name, party_id) FROM '<path_to_csv_files>/candidates.csv' WITH (FORMAT csv, HEADER true);
COPY elections (id, name, year, type, start_date, end_date) FROM '<path_to_csv_files>/elections.csv' WITH (FORMAT csv, HEADER true);
COPY state_election_results (id, election_id, state_id, winner_id, total_votes, candidate_votes) FROM '<path_to_csv_files>/state_election_results.csv' WITH (FORMAT csv, HEADER true);
COPY county_election_results (id, election_id, county_id, winner_id, total_votes, candidate_votes) FROM '<path_to_csv_files>/county_election_results.csv' WITH (FORMAT csv, HEADER true);
COPY city_election_results (id, election_id, city_id, winner_id, total_votes, candidate_votes) FROM '<path_to_csv_files>/city_election_results.csv' WITH (FORMAT csv, HEADER true);
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
// Remove data from the tables
await queryRunner.query(`
TRUNCATE city_election_results, county_election_results, state_election_results, elections, candidates, parties, cities, counties, states;
`);
}
}