Terra Docs
Dashboard
  • Docs
  • API Reference
  • Changelog
  • Getting Started
    • What is Terra API?
    • Account setup and API keys
    • Core concepts
  • Health & Fitness API
    • Overview
    • Quickstart
    • Integration setup
      • Understanding sources and destinations
      • Setting up data sources
      • Setting up data destinations
        • Webhooks
        • SQL database (Postgres, MySQL)
        • Supabase
        • Cloud storage (S3, GCP)
        • Queuing services (SQS, Kafka)
      • Customising data types
      • Dedicated data source API keys
      • Understanding Terra environments
    • User authentication
      • Authentication flow
      • Implementation (Terra widget)
      • Implementation (Custom UI)
      • Handling authentication events
      • Customising authentication redirects
    • Managing user health data
      • Receiving health data updates (events)
      • Requesting historical health data (REST API requests)
      • Writing data
    • Mobile-only sources
      • iOS (Swift)
      • Android (Kotlin)
      • React Native
      • Flutter
    • Troubleshooting
    • Pricing
  • User Engagement
    • Health Scores
  • Streaming API
    • Overview
    • Wearable -> Your app
      • iOS (Swift)
      • Android
    • Your app -> Terra
      • iOS (Swift)
      • Android
    • Terra -> Your backend
  • Teams API
  • Biomarkers API - Upcoming
Powered by GitBook
On this page
  • Setup
  • Data Structure

Was this helpful?

  1. Health & Fitness API
  2. Integration setup
  3. Setting up data destinations

SQL database (Postgres, MySQL)

PreviousWebhooksNextSupabase

Last updated 1 month ago

Was this helpful?

SQL databases are easy to set up and often the go-to choices for less abstracted storage solutions. Terra currently supports Postgres & MySQL.

Setup

You will need to ensure your SQL database is publicly accessible. As a security measure, you may implement using the list of IPs above.

Next, create a user with enough permissions to create tables & have read & write access within those tables. You can execute the scripts below based on your database

CREATE USER terra_user WITH PASSWORD 'your_password';
GRANT CONNECT ON DATABASE your_database_name TO terra_user;
GRANT USAGE ON SCHEMA public TO terra_user;
GRANT CREATE ON SCHEMA public TO terra_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public 
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO terra_user;
CREATE USER 'terra_user'@'%' IDENTIFIED BY 'your_password';
GRANT CREATE, SELECT, INSERT, UPDATE, DELETE ON your_database_name.* TO 'terra_user'@'%';
REVOKE ALL PRIVILEGES ON your_database_name.existing_table FROM 'terra_user'@'%';

Data Structure

Data will be stored in tables within your SQL database following the structure below:

Users will be created in the terra_users table, data payloads will be placed in the terra_data_payloads, and all other payloads sent will be added to the terra_other_payloads.

When using as a destination, Terra handles data storage for you. All data payloads will be stored in a Terra-owned S3 bucket, and the download link for each payload will be found under the payload_url column

SQL
IP whitelisting