{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "PostgreSQL Catalog History dataset",
  "type": "object",
  "required": [
    "schema_version",
    "snapshot_date",
    "versions",
    "relations",
    "transitions",
    "stats",
    "provenance"
  ],
  "properties": {
    "schema_version": {
      "const": "1.0"
    },
    "snapshot_date": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "versions": {
      "type": "array",
      "minItems": 17,
      "items": {
        "$ref": "#/$defs/version"
      }
    },
    "relations": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/relation"
      }
    },
    "transitions": {
      "type": "array",
      "minItems": 16
    },
    "stats": {
      "type": "object"
    },
    "provenance": {
      "type": "object"
    }
  },
  "$defs": {
    "column": {
      "type": "object",
      "required": [
        "name",
        "type",
        "description",
        "type_oid",
        "attnum",
        "not_null",
        "hidden",
        "type_modifier",
        "array_dimensions"
      ],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^[a-z_][a-z_0-9]*$"
        },
        "type": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "references": {
          "type": "string"
        },
        "hidden": {
          "type": "boolean"
        },
        "source_url": {
          "type": "string"
        },
        "documented_name": {
          "type": "string"
        },
        "documented_type": {
          "type": "string"
        },
        "type_oid": {
          "type": "integer"
        },
        "attnum": {
          "type": "integer"
        },
        "type_modifier": {
          "type": "integer"
        },
        "array_dimensions": {
          "type": "integer"
        },
        "not_null": {
          "type": "boolean"
        }
      }
    },
    "snapshot": {
      "type": "object",
      "required": [
        "description",
        "columns",
        "source_url",
        "runtime_validation",
        "system_columns",
        "shared",
        "relkind"
      ],
      "properties": {
        "description": {
          "type": "string"
        },
        "source_url": {
          "type": "string",
          "pattern": "^https://"
        },
        "columns": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/column"
          }
        },
        "runtime_validation": {
          "type": "object",
          "required": [
            "release",
            "source_tag",
            "source_path",
            "sha256",
            "passed"
          ],
          "properties": {
            "passed": {
              "const": true
            },
            "sha256": {
              "type": "string",
              "pattern": "^[0-9a-f]{64}$"
            }
          }
        },
        "system_columns": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "name",
              "type",
              "attnum",
              "type_oid",
              "hidden"
            ]
          }
        }
      }
    },
    "version": {
      "type": "object",
      "required": [
        "id",
        "label",
        "status",
        "source_tag",
        "relation_count",
        "column_count"
      ],
      "properties": {
        "id": {
          "type": "string",
          "enum": [
            "9.0",
            "9.1",
            "9.2",
            "9.3",
            "9.4",
            "9.5",
            "9.6",
            "10",
            "11",
            "12",
            "13",
            "14",
            "15",
            "16",
            "17",
            "18",
            "19"
          ]
        },
        "label": {
          "type": "string"
        },
        "status": {
          "enum": [
            "historical",
            "stable",
            "preview"
          ]
        },
        "source_tag": {
          "type": "string"
        },
        "relation_count": {
          "type": "integer",
          "minimum": 1
        },
        "column_count": {
          "type": "integer",
          "minimum": 1
        }
      }
    },
    "change": {
      "type": "object",
      "required": [
        "from",
        "to",
        "status",
        "added_columns",
        "removed_columns",
        "type_changes",
        "description_changes",
        "structural"
      ],
      "properties": {
        "from": {
          "type": "string"
        },
        "to": {
          "type": "string"
        },
        "status": {
          "enum": [
            "added",
            "removed",
            "changed"
          ]
        },
        "added_columns": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/column"
          }
        },
        "removed_columns": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/column"
          }
        },
        "type_changes": {
          "type": "array"
        },
        "description_changes": {
          "type": "array"
        },
        "structural": {
          "type": "boolean"
        }
      }
    },
    "relation": {
      "type": "object",
      "required": [
        "name",
        "kind",
        "summary",
        "first_version",
        "last_version",
        "versions",
        "changes"
      ],
      "properties": {
        "name": {
          "type": "string",
          "pattern": "^pg_[a-z_0-9]+$"
        },
        "kind": {
          "enum": [
            "catalog",
            "view",
            "statistics",
            "progress"
          ]
        },
        "summary": {
          "type": "string"
        },
        "first_version": {
          "type": "string"
        },
        "last_version": {
          "type": "string"
        },
        "versions": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": {
            "$ref": "#/$defs/snapshot"
          }
        },
        "changes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/change"
          }
        }
      }
    }
  }
}
