Database Schema & Models
Relevant source files
The following files were used as context for generating this wiki page:
The Actionmap application utilizes a relational database to manage information regarding political representatives, geographical entities (states and counties), user interactions, and news items. The system is designed to provide a mapping between administrative regions and the officials who represent them, while allowing users to track and rate news articles related to specific political issues.
The persistence layer is built on ActiveRecord, supporting multiple database adapters including SQLite3 for development and testing, and PostgreSQL for production environments. The schema defines clear relationships between geography (States -> Counties), representation (Representatives -> News Items), and user-generated content (Users -> Ratings).
Database Configuration
The application supports environment-specific database configurations. Development and testing environments use SQLite3, while the production environment is configured for PostgreSQL.
| Environment | Adapter | Database/URL |
|---|---|---|
| Development | sqlite3 | db/development.sqlite3 |
| Test | sqlite3 | db/test.sqlite3 |
| Production | postgresql | Derived from DATABASE_URL |
Sources: config/database.yml:29-57, config/application.rb:26-28
Entity Relationship Overview
The following diagram illustrates the primary entities and their relationships within the Actionmap system.
The schema establishes a hierarchical geographical structure and a separate structure for political representation and user feedback.
Sources: db/schema.rb:14-100
Core Data Models
Geographical Models
The application tracks administrative divisions to localize news and events. States contain multiple counties, which are the base unit for local events.
| Model | Field | Type | Constraints |
|---|---|---|---|
| State | name | string | null: false |
| symbol | string | null: false | |
| fips_code | integer | limit: 1, null: false | |
| is_territory | integer | null: false | |
| lat_min/max | float | null: false | |
| County | name | string | null: false |
| state_id | integer | null: false, index | |
| fips_code | integer | limit: 2, null: false |
Sources: db/schema.rb:14-23, db/schema.rb:71-82
Political Representation & News
The representatives table stores information about officials, while news_items links these officials to specific media coverage and political issues.
| Model | Field | Type | Description |
|---|---|---|---|
| Representative | name | string | Full name of the official |
| ocdid | string | Open Civic Data Identifier | |
| party | string | Political affiliation | |
| address | string | Official contact address | |
| NewsItem | title | string | Headline of the news item |
| link | string | URL to the article | |
| representative_id | integer | Foreign key to representatives | |
| issue | string | The specific political topic |
Sources: db/schema.rb:40-50, db/schema.rb:58-68
Data Persistence & Session Management
The application utilizes ActiveRecord::SessionStore to persist user sessions in the database rather than using cookies for data storage. This is configured in the application initialization.
The sessions table includes a unique session_id and a data text field for serialized session information.
Sources: config/application.rb:27, db/schema.rb:51-57
Data Flow: News Item Selection and Rating
A specialized flow exists for users to find and rate news items for representatives. This involves temporary storage in the session before persisting a rating.
This flow allows users to interact with external news data and record their personal sentiment (rating) against specific articles within the local database.
Sources: app/controllers/my_news_items_controller.rb:16-56, db/schema.rb:31-39
Seed and Task Integration
The database is populated using seed scripts that ingest JSON and CSV data to establish the initial state and county records.
- Geographical Seeding: Reads from
lib/assets/counties_fips_data/to link counties to their parent states viastate_id. - Shapefile Requests: The
StateShapefileRequestclass manages the metadata for geographical boundaries (TopoJSON/GeoJSON), linking FIPS codes in the database to external spatial files.
Sources: db/seeds.rb:16-25, lib/task_helpers/state_shapefile_request.rb:21-30
Conclusion
The Actionmap database schema is structured to support a localized political information system. By separating geographical data (States/Counties) from representation (Representatives/NewsItems) and user interactions (Users/Ratings), the system provides a robust framework for tracking political discourse at various administrative levels. The use of an ActiveRecord-backed session store and explicit FIPS code tracking ensures data consistency across geographical and political queries.