Database schema and migrations for M-OBS (Mantle Observability Stack).
GitHub: https://github.com/hackonteam/m-obs-database
Main Project: https://github.com/hackonteam/m-obs
This repository contains all database migrations and schema definitions for the M-OBS project. The database is deployed on Supabase PostgreSQL and provides storage for:
- RPC endpoint registry and health monitoring
- Transaction records and traces
- Real-time metrics aggregation
- Alert rules and events
- Contract watchlist
-
rpc_endpoints- RPC provider registry- Provider URLs and metadata
- Health scores and status
- Trace API support detection
-
rpc_health_samples- Time-series health data- Latency measurements
- Availability tracking
- Historical performance data
-
contracts- Contract watchlist- Tracked contract addresses
- ABI definitions
- Metadata and labels
-
txs- Transaction records- Focus on failed transactions
- Error signatures and decoded messages
- Gas usage and status
-
tx_traces- Execution traces- Optional detailed execution data
- Call stack information
- Bounded retention (7 days)
-
metrics_minute- Pre-aggregated metrics- Per-minute rollup data
- Transaction counts and failure rates
- Gas price statistics
- Top errors tracking
-
alerts- Alert rule definitions- User-defined alert rules
- Threshold configurations
- Alert types: failure_rate, gas_spike, provider_down
-
alert_events- Alert trigger history- Alert event records
- Cooldown enforcement
- Historical alert data
-
worker_state- Worker coordination- Last processed block tracking
- Worker heartbeats
- State checkpoints for recovery
The migrations are located in supabase/migrations/ and numbered sequentially:
supabase/migrations/
├── 00001_create_rpc_endpoints.sql
├── 00002_create_rpc_health_samples.sql
├── 00003_create_contracts.sql
├── 00004_create_txs.sql
├── 00005_create_tx_traces.sql
├── 00006_create_metrics_minute.sql
├── 00007_create_alerts.sql
├── 00008_create_alert_events.sql
├── 00009_create_worker_state.sql
├── 00010_seed_rpc_endpoints.sql
└── 00011_create_retention_policies.sql
00001 - RPC Endpoints
- Creates
rpc_endpointstable - Indexes on
is_activeandhealth_score
00002 - RPC Health Samples
- Creates
rpc_health_samplestable - Index on
(endpoint_id, sampled_at)for time-series queries - Foreign key to
rpc_endpoints
00003 - Contracts
- Creates
contractstable - Unique constraint on
address - Index for active contract queries
00004 - Transactions
- Creates
txstable - Indexes optimized for filtering:
- Status queries
- Time range queries
- Contract and address lookups
- Error signature searches
00005 - Transaction Traces
- Creates
tx_tracestable - Bounded retention (7 days default)
- Optional detailed execution data
00006 - Metrics (Minute)
- Creates
metrics_minutetable - Unique constraint on
(bucket_start) - Index for time-series queries
- Stores pre-aggregated metrics
00007 - Alerts
- Creates
alertstable - Alert rule definitions
- Threshold configurations
00008 - Alert Events
- Creates
alert_eventstable - Index on
(alert_id, triggered_at) - Historical alert tracking
00009 - Worker State
- Creates
worker_statetable - Worker coordination and checkpoints
- Unique constraint on
worker_name
00010 - Seed Data
- Seeds initial RPC endpoints for Mantle mainnet:
00011 - Retention Policies
- Creates cleanup functions:
cleanup_old_health_samples()- Removes samples older than 30 dayscleanup_old_metrics()- Removes metrics older than 90 dayscleanup_old_tx_traces()- Removes traces older than 7 dayscleanup_old_alert_events()- Removes events older than 30 days
- Supabase account (https://supabase.com)
- Supabase CLI installed:
npm install -g supabase
-
Create Supabase Project
# Create project at https://supabase.com # Note your project reference ID
-
Link to Project
cd supabase supabase link --project-ref <your-project-ref>
-
Apply Migrations
supabase db push
-
Verify Setup
# Check tables created supabase db list
After deployment, configure your backend services with the connection details:
# Get from Supabase dashboard > Settings > Database
DATABASE_URL=postgresql://postgres:[YOUR-PASSWORD]@db.[YOUR-PROJECT-REF].supabase.co:5432/postgresOr use Supabase client libraries:
SUPABASE_URL=https://[YOUR-PROJECT-REF].supabase.co
SUPABASE_KEY=[YOUR-SERVICE-ROLE-KEY]All tables have optimized indexes for:
- Time-series queries (using
sampled_at,created_at,bucket_start) - Foreign key lookups
- Status and type filtering
- Full-text search readiness
- Foreign keys with CASCADE delete for related data
- Unique constraints for deduplication
- Check constraints for data validation
- NOT NULL constraints for required fields
Automated cleanup functions remove old data:
- Health samples: 30 days
- Metrics: 90 days
- Transaction traces: 7 days
- Alert events: 30 days
Schedule these functions to run periodically:
-- Example: Run daily via cron job or Supabase Edge Functions
SELECT cleanup_old_health_samples();
SELECT cleanup_old_metrics();
SELECT cleanup_old_tx_traces();
SELECT cleanup_old_alert_events();# Create new migration
cd supabase
supabase migration new <migration_name>
# Edit the created file in supabase/migrations/
# Test locally
supabase db reset # Resets local database
supabase db push # Applies migrations
# Push to production
supabase db push --linked- Incremental Changes: Each migration should be atomic
- Backwards Compatible: Avoid breaking changes when possible
- Rollback Plan: Document how to reverse changes
- Test Locally: Always test migrations before production
- Data Migration: Separate schema changes from data migrations
# Start local Supabase
supabase start
# Apply migrations locally
supabase db push
# Reset local database
supabase db reset
# Stop local Supabase
supabase stop┌─────────────────┐
│ rpc_endpoints │
└────────┬────────┘
│
▼
┌─────────────────────┐
│ rpc_health_samples │
└─────────────────────┘
┌─────────────┐
│ contracts │
└──────┬──────┘
│
▼
┌─────────────┐ ┌──────────────┐
│ txs │─────►│ tx_traces │
└─────────────┘ └──────────────┘
┌─────────────────┐
│ metrics_minute │
└─────────────────┘
┌─────────────┐
│ alerts │
└──────┬──────┘
│
▼
┌─────────────────┐
│ alert_events │
└─────────────────┘
┌─────────────────┐
│ worker_state │
└─────────────────┘
- Total Migrations: 11
- Total Tables: 9
- Total Indexes: 20+
- Storage Features: Time-series optimized, automated retention
- Main Repository: https://github.com/hackonteam/m-obs
- Backend (API + Worker): https://github.com/hackonteam/m-obs-backend
- Frontend (Web App): https://github.com/hackonteam/m-obs-frontend
HackOn Team Vietnam
- Bernie Nguyen - Founder/Leader/Full-stack/Main developer
- Thien Vo - Front-end developer intern
- Canh Trinh - Researcher, Back-end developer intern
- Sharkyz Duong Pham - Business developer lead
- Hieu Tran - Business developer
Collaboration: Phu Nhuan Builder
Contact:
- Email: work.hackonteam@gmail.com
- Telegram: https://t.me/hackonteam
MIT License - see LICENSE file
Copyright (c) 2026 HackOn Team Vietnam and Phu Nhuan Builder
Contributions are welcome! To contribute:
- Fork this repository
- Create a new migration file
- Test locally with
supabase db reset && supabase db push - Submit a pull request
Make sure migrations are:
- Properly numbered
- Idempotent when possible
- Well-documented
- Tested locally
For issues or questions:
- Open an issue in the main repository: https://github.com/hackonteam/m-obs/issues
- Contact: work.hackonteam@gmail.com