Logo

dev-resources.site

for different kinds of informations.

DBOS-Cloud: Minimal Effort Change Data Capture (CDC) Tool

Published at
7/28/2024
Categories
dbos
workflows
postgres
orchestration
Author
vince_hirefunnel_co
Author
19 person written this
vince_hirefunnel_co
open
DBOS-Cloud: Minimal Effort Change Data Capture (CDC) Tool

This is a simple DBOS example focusing on remote deployment to DBOS Cloud, their hosted solution with a generous free tier for devs.

The github repo sets up: 1) a workflow with an http api endpoint that receives events from Supabase when an INSERT is made to a table, 2) the same workflow archives the event payload to a DBOS hosted Postgres table, and 3) additional endpoints as utilities to view and delete all events while in development.

Prerequisites

  1. Make sure you have node.js 21.x

  2. Sign up for DBOS Cloud (https://www.dbos.dev/dbos-cloud)

  3. Have a Supabase account and a table you are inserting in to.

Getting Started

  1. Clone the repository and navigate to the project directory

  2. Install the dependencies

    Be sure not to commit / hard code your secrets to a public repo! This setup is meant for local development and direct deployment to the dbos-cloud service.

  3. To deploy to DBOS-cloud, login with this, "npx dbos-cloud login" and follow the instructions to match the uuid given in the console to the one in the browser, then standard login user/password applies.

  4. Next provision a d'base instance: "npx dbos-cloud db provision database-instance-name -U database-username"

  5. Register your app with the d'base instance: "npx dbos-cloud app register -d database-instance-name"

  6. To use secrets in DBOS, add your variables in the cli like this:

export PGPASSWORD=put-the-password-you-created-when-you-setup-the-remote-database-here

These will be picked up at build time and inserted into the dbos-config.yaml fields: ${PGPASSWORD}.

You will notice on line #56 of operations.ts, there is a @PostApi decorator which sets up a url with a randomly generated endpoint. This will be the receiver of events from Supabase. I created the randomly generated endpoint to protect the api (sometimes called protection by obfuscation).

**Note: this is not a recommended method! It was done as a quick and dirty dev hack. For real production use, you will want to use DBOS' authentication / authorization features **

Take the base url that DBOS returned when the deploy finished and add the randomly generated endpoint you create (instructions are in the code).

It should look something like this: https://foo-bar-dbos.cloud.dbos.dev/OBstAqG6qOv7cWXCqgg. You'll use this in the next step.


The Supabase settings

On the Supabase side, set up the trigger to publish changes externally by: 1) choosing the project you want to use, then on the left hand side menu go to "Database" --> "Webhooks". 2) create a new webhook, give it a name, choose the table to watch, and the events (in our case insert, but update and delete are also available). Make sure the http request method is set to POST, then enter the URL created by DBOS-Cloud plus the randomly generated stub. Hit "Create Webhook".

Staying in the Supabase console, go to the "Table Editor", choose your table, and add a new row with the required inputs.

Almost immediately, you should be able to query in Insomnia / Postman or curl given your specific DBOS supplied url, https://foo-bar-dbos.cloud.dbos.dev/getEventData, and see the event.

For reference, here is the format of a sample event body sent to DBOS-Cloud:

{

    "type": "INSERT",

    "table": "fooData",

    "record": {

        "id": "tempId-e71m1dtxan6b5c0dqxkbhoez",

        "email": "[email protected]",

        "lastName": "Blow",

        "firstName": "Joe",

        "created_at": "2024-07-25T06:03:10.792595+00:00",

        "updated_at": "2024-07-25T06:03:10.792595"

},

    "schema": "public",

    "old_record": null

}
Enter fullscreen mode Exit fullscreen mode

Record fields will vary based on how your table is structured. For simplicity purposes, in this example, I archive the JSON object in total vs. parsing the records further.


Reference Docs (From Official Repo)


Resources to learn more --

Awesome-dbos

The first article in this series uses cron and Postmark email service provider.

The second article in this series aggregates and archives data from Supabase tables.

workflows Article's
30 articles in total
Favicon
Security Teams : Automate Cybersecurity Workflows
Favicon
GitHub Action security hardening with OpenID (OIDC) Connect - "Password-Less"
Favicon
Optimizing Test Coverage for Oracle OTM Workflows
Favicon
Continuous Integration
Favicon
DBOS-Cloud Simple and Robust Workflow Orchestration
Favicon
DBOS-Cloud: Minimal Effort Change Data Capture (CDC) Tool
Favicon
DBOS-Cloud: Fast and Free Automatic Data Aggregator
Favicon
DBOS-Cloud: Fast and Free Automatic Supabase Table Copier
Favicon
Part 1 - LittleHorse Advanced Concept Series: Conditionals
Favicon
Free & Paid Notion templates, covers, tools and more!
Favicon
Announcing WDL 1.1.1
Favicon
Visualize and Inspect Workflows Executions
Favicon
Simplifying Workflow Management with the XWorkflows Library
Favicon
How to use GitHub Workflows to Streamline Your Software Development Process
Favicon
Building Autonomous Business Processes using AI Agent Workflows
Favicon
📦 Stay Organized and Efficient with Auto-Label-Pulls Github Action
Favicon
Temporal for VS Code
Favicon
Using the Temporal CLI
Favicon
Getting Started With Apache Airflow
Favicon
Getting Started with n8n: Integrating Typeform and Slack for Dynamic Messaging
Favicon
Calculating your potential reach on Mastodon with Google Cloud Workflows orchestrating the Mastodon APIs
Favicon
Simple Github Workflow for Lint - Prettier & Jest (yarn)
Favicon
How to view fields in an unauthorized connector's action cards
Favicon
All Okta Workflows Community-Created Flows
Favicon
Okta Workflows Connector Builder
Favicon
Manage Short Term Users with Okta Workflows
Favicon
GraphQL queries with Okta Workflows
Favicon
Event Hook Filtering and Okta Workflows
Favicon
Pagination with Okta Workflows
Favicon
A Flow to Audit Inactive Google Workspace Users in Okta

Featured ones: