#share database with other app

1 messages · Page 1 of 1 (latest)

cursive kiln
#

if i self-host convex and set an external database (in this case postgres), i would then share it with another app that also uses the same database. how do i avoid overwriting the tables and data of the other app (keeping read-only from convex) but also being able to read them without manually writing out the schemas for the other table

wheat hollowBOT
#

Hi @cursive kiln. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Convex doesn’t document a way to automatically infer schemas from an existing Postgres database; you still define Convex’s schema yourself in schema.ts. The self‑hosting docs assume Convex “owns” the convex_self_hosted database (or another DB matching the instance name) and don’t cover sharing that DB with another app’s tables. [Self-hosted DB]

A few relevant points from the docs and articles:

  1. Convex expects its own logical schema

    • The Convex backend persists to a DB named convex_self_hosted (or one derived from INSTANCE_NAME). It connects via POSTGRES_URL/MYSQL_URL, and you create that DB specifically for Convex. [Self-hosted DB]
    • Nothing in the docs indicates support for co‑habiting an existing app DB and automatically discovering its tables/columns.
  2. Convex schema is always declared in code

    • You define tables and indexes in schema.ts, optionally with looser typings via strictTableNameTypes: false. [Schema options]
    • Even with strictTableNameTypes: false, Convex still only validates documents in tables listed in the schema; it does not dynamically reflect the external DB schema.
  3. Read‑only tables are done by convention, not enforcement

    • For imported or mirrored data (e.g. via Airbyte), Convex recommends treating those tables as read‑only by not writing to them from mutations or the dashboard. There is no built‑in “read‑only table” flag yet. [Streaming import/export]
#
  1. Recommended pattern for “external” data
    When Convex mirrors data from another system (via Airbyte, etc.), the docs recommend:
    • Import/mirror into separate Convex tables.
    • Treat those tables as read‑only.
    • Use Convex queries/mutations against that mirrored shape. [Streaming import/export]

Given all that, based on the available docs:

  • There is no documented way to point Convex at an existing Postgres database used by another app, auto‑discover its tables, and safely guarantee Convex is read‑only against them.
  • There is no documented feature to avoid writing a schema while still being able to type‑safely read arbitrary external tables.

The safest setup the docs support today is:

  1. Give Convex its own database (recommended):

    • Use a dedicated Postgres DB (e.g. convex_self_hosted) for Convex only. [Self-hosted DB]
    • Integrate the other app’s DB via:
      • Streaming import/export (Airbyte/Fivetran) and treat those Convex tables as read‑only. [Streaming import/export]
      • Or HTTP/webhook–style actions that read from the external app and write into Convex’s own tables.
  2. If you still share the same physical Postgres instance:

    • Use a separate database name for Convex (e.g. convex_self_hosted) so Convex doesn’t touch the other app’s DB at all. [Self-hosted DB]
    • Let the other app keep its own DB/schema; Convex only uses its own DB within the same server.
#
  1. If you mirror external tables into Convex:
    • You must still define a Convex schema for those mirrored tables (shape, fields, ids). There’s no documented auto‑schema import. [Schema options; Streaming import/export]
    • Make them read‑only by convention (no mutations/actions that write to them).

So, with the current docs, your specific goal:

“share it with another app that also uses the same database … keep read-only from convex … read them without manually writing out the schemas”

is not directly supported. The documented, supported path is to keep Convex on its own logical database and, if needed, mirror or stream the other app’s data into Convex‑managed tables where you do define a schema.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: