{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://gmr.github.io/pglifecycle/schemata/publication.json",
  "title": "Publication",
  "description": "A publication is essentially a group of tables whose data changes are intended to be replicated through logical replication.\n",
  "type": "object",
  "properties": {
    "name": {
      "title": "Publication Name",
      "description": "The name of the publication to create",
      "type": "string"
    },
    "tables": {
      "title": "Tables for Replication",
      "description": "The tables to publish, each exactly the table named: an inheritance child is listed on its own, as pg_dump writes it. A table is its qualified name, or an object that also limits the columns or rows published.\n",
      "type": "array",
      "items": {
        "oneOf": [
          {
            "title": "Table Name",
            "type": "string"
          },
          {
            "title": "Filtered Table",
            "type": "object",
            "properties": {
              "name": {
                "title": "Table Name",
                "type": "string"
              },
              "columns": {
                "title": "Columns",
                "description": "The columns to publish",
                "type": "array",
                "items": {
                  "type": "string"
                },
                "minItems": 1
              },
              "where": {
                "title": "Row Filter",
                "description": "The rows to publish, a boolean expression",
                "type": "string"
              }
            },
            "required": [
              "name"
            ],
            "additionalProperties": false
          }
        ]
      },
      "minItems": 1
    },
    "schemas": {
      "title": "Schemas for Replication",
      "description": "Publish every table in these schemas, including tables created later (FOR TABLES IN SCHEMA).\n",
      "type": "array",
      "items": {
        "type": "string"
      },
      "minItems": 1
    },
    "all_tables": {
      "title": "Replicate All Tables",
      "description": "Use to replicate all tables",
      "type": "boolean"
    },
    "parameters": {
      "title": "Publication Parameters",
      "type": "object",
      "properties": {
        "publish": {
          "title": "Publish",
          "description": "This parameter determines which DML operations will be published by the new publication to the subscribers.\n",
          "type": "array",
          "items": {
            "title": "Operation",
            "type": "string",
            "enum": [
              "insert",
              "update",
              "delete",
              "truncate"
            ]
          }
        },
        "publish_via_partition_root": {
          "title": "Publish Via Partition Root",
          "description": "Publish changes to a partition as changes to its partitioned root table.\n",
          "type": "boolean"
        },
        "publish_generated_columns": {
          "title": "Publish Generated Columns",
          "description": "Whether stored generated columns are published (PostgreSQL 18).\n",
          "enum": [
            "none",
            "stored"
          ]
        }
      },
      "additionalProperties": false
    },
    "comment": {
      "title": "Comment",
      "description": "An optional comment about the publication",
      "type": "string"
    }
  },
  "required": [
    "name"
  ],
  "additionalProperties": false,
  "not": {
    "required": [
      "all_tables"
    ],
    "anyOf": [
      {
        "required": [
          "tables"
        ]
      },
      {
        "required": [
          "schemas"
        ]
      }
    ]
  }
}