Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

568 B
Raw Blame
import { ident, joinSqlFragments, safeSql, type SafeSqlFragment } from '../../../pg-format'

export const getCreatePublicationSQL = ({
  name,
  tables,
}: {
  name: string
  tables: { schema: string; name: string }[]
}): SafeSqlFragment => {
  const query =
    tables.length > 0
      ? safeSql`FOR TABLE ONLY ${joinSqlFragments(
          tables.map(({ schema, name }) => safeSql`${ident(schema)}.${ident(name)}`),
          ', '
        )} `
      : safeSql``

  return safeSql`CREATE PUBLICATION ${ident(name)} ${query}WITH (publish_via_partition_root = true)`
}