Database Setup
Prerequisites
- PostgreSQL installed locally
- Database created (e.g.,
koin_ping_dev)
Setup Steps
1. Create Database
# Using psql
createdb koin_ping_dev
# Or via psql command line
psql -U postgres
CREATE DATABASE koin_ping_dev;
\q
2. Set Environment Variables
Create a .env file in the backend/ directory:
DATABASE_URL=postgresql://your_user:your_password@localhost:5432/koin_ping_dev
Or if using individual variables (for infra/database.js):
DB_HOST=localhost
DB_PORT=5432
DB_USER=your_user
DB_PASSWORD=your_password
DB_NAME=koin_ping_dev
3. Run Schema
# From the backend
psql -d koin_ping_dev -f db/schema.sql
# Or the full connection string
psql postgresql://your_user:your_password@localhost:5432/koin_ping_dev -f db/schema.sql
4. Verify Tables
psql -d koin_ping_dev
# In psql:
\dt # List tables
\d addresses # Describe addresses table
\d alert_rules # Describe alert_rules table
\d alert_events # Describe alert_events table
Tables
addresses
id- Primary keyaddress- Ethereum address (unique)label- Optional display namecreated_at- Timestamp
alert_rules
id- Primary keyaddress_id- Foreign key to addressestype- Alert type:incoming_tx,outgoing_tx,large_transfer,balance_belowthreshold- ETH amount (nullable)enabled- Active statuscreated_at- Timestamp
alert_events
id- Primary keyalert_rule_id- Foreign key to alert_rulesmessage- Alert descriptionaddress_label- Denormalized label for displaytimestamp- When alert fired
Reset Database
To start fresh:
psql -d koin_ping_dev -f db/schema.sql
The schema includes DROP TABLE IF EXISTS statements for clean reruns.