ETL: From Supabase to RDS using Mage¶
Source Database¶
Create a user in the source database (Supabase).¶
CREATE USER mage WITH PASSWORD 'source_password' -- replace password
REPLICATION -- for change data capture
BYPASSRLS; -- to bypass row level security
GRANT pg_read_all_data TO mage; -- default postgres role for reading all data
public schema: GRANT USAGE ON SCHEMA public TO mage;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mage;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO mage;
-- Set Default Permissions for New Objects in Public Schema
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO mage;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT EXECUTE ON FUNCTIONS TO mage;
Create a replication slot.¶
Create a publication for all tables.¶
Destination Database¶
Create a schema in the destination database (PostgreSQL).¶
Create a user in the destination database.¶
CREATE USER mage_destination_user WITH PASSWORD 'mage_password'; -- replace with the proper user, for example, use `mage_tools` for the `tools` schema
Grant permissions in the destination database.¶
-- Grant USAGE and CREATE privileges on the schema `new_schema`
GRANT USAGE, CREATE ON SCHEMA new_schema TO mage_destination_user;
-- Grant ALL PRIVILEGES on all tables in the schema `new_schema`
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA new_schema TO mage_destination_user;
-- Grant ALL PRIVILEGES on all sequences in the schema `new_schema`
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA new_schema TO mage_destination_user;
-- Ensure future tables and sequences in the schema `new_schema` have the necessary privileges
ALTER DEFAULT PRIVILEGES IN SCHEMA new_schema GRANT ALL PRIVILEGES ON TABLES TO mage_destination_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA new_schema GRANT ALL PRIVILEGES ON SEQUENCES TO mage_destination_user;
-- Grant CREATE privilege on the database to allow creating schemas
GRANT CREATE ON DATABASE your_database_name TO mage_destination_user;
Data integration pipeline¶
Follow this guide to create a data integration pipeline in Mage.
However, choose PostgreSQL as the source and choose LOG_BASED as the replication method.
The Supabase database must have an IPv4 ($4/mo), and we must use the direct connection (not the pooler). Source