{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://json.schemastore.org/pyrseas-0.8.json",
  "definitions": {
    "onePriv": {
      "oneOf": [
        {
          "type": "string",
          "enum": [
            "all",
            "insert",
            "delete",
            "select",
            "update",
            "truncate",
            "references",
            "trigger",
            "usage",
            "execute",
            "create"
          ]
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "all": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "insert": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "delete": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "select": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "update": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "truncate": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "references": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "trigger": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "usage": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "execute": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "create": {
              "additionalProperties": false,
              "properties": {
                "grantable": {
                  "type": "boolean"
                }
              }
            }
          }
        }
      ]
    },
    "privileges": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": {
          "oneOf": [
            {
              "type": "array",
              "items": {
                "$ref": "#/definitions/onePriv"
              }
            },
            {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "grantor": {
                  "type": "string"
                },
                "privs": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/onePriv"
                  }
                }
              }
            }
          ]
        }
      }
    },
    "db": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^schema ": {
          "$ref": "#/definitions/schema"
        },
        "^cast ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "context": {
              "type": "string"
            },
            "method": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "function": {
              "type": "string"
            },
            "depends_on": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "^extension ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "description": {
              "type": "string"
            },
            "owner": {
              "type": "string"
            },
            "schema": {
              "type": "string"
            },
            "version": {
              "type": "string"
            }
          }
        },
        "^event trigger ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "description": {
              "type": "string"
            },
            "enabled": {
              "type": "boolean"
            },
            "event": {
              "type": "string"
            },
            "procedure": {
              "type": "string"
            },
            "tags": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "owner": {
              "type": "string"
            }
          }
        },
        "^foreign data wrapper ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "description": {
              "type": "string"
            },
            "validator": {
              "type": "string"
            },
            "options": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "handler": {
              "type": "string"
            },
            "owner": {
              "type": "string"
            },
            "privileges": {
              "$ref": "#/definitions/privileges"
            }
          }
        },
        "^language ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "description": {
              "type": "string"
            },
            "trusted": {
              "type": "boolean"
            },
            "owner": {
              "type": "string"
            },
            "privileges": {
              "$ref": "#/definitions/privileges"
            }
          }
        }
      }
    },
    "schema": {
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^table ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "owner": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "columns": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "default": {
                      "type": "string"
                    },
                    "not_null": {
                      "type": "boolean"
                    },
                    "inherited": {
                      "type": "boolean"
                    },
                    "collation": {
                      "type": "string"
                    },
                    "statistics": {
                      "type": "integer"
                    },
                    "identity": {
                      "type": "string",
                      "enum": ["always", "by default"]
                    },
                    "description": {
                      "type": "string"
                    }
                  }
                }
              }
            },
            "unique_constraints": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "columns": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            },
            "foreign_keys": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "columns": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "on_delete": {
                    "type": "string"
                  },
                  "on_update": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "references": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "columns": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "schema": {
                        "type": "string"
                      },
                      "table": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            },
            "check_constraints": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "columns": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "expression": {
                    "type": "string"
                  },
                  "inherited": {
                    "type": "boolean"
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            },
            "primary_key": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "columns": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "cluster": {
                    "type": "boolean"
                  }
                }
              }
            },
            "indexes": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "keys": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "access_method": {
                    "type": "string"
                  },
                  "unique": {
                    "type": "boolean"
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            },
            "triggers": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "events": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "level": {
                    "type": "string"
                  },
                  "procedure": {
                    "type": "string"
                  },
                  "timing": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            },
            "inherits": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "unlogged": {
              "type": "boolean"
            },
            "options": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "partition_bound_spec": {
              "type": "string"
            },
            "partition_by": {
              "type": "string"
            },
            "partition_cols": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "partition_exprs": {
              "type": "string"
            },
            "tablespace": {
              "type": "string"
            },
            "rules": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "actions": {
                    "type": "string"
                  },
                  "condition": {
                    "type": "string"
                  },
                  "event": {
                    "type": "string"
                  },
                  "instead": {
                    "type": "boolean"
                  },
                  "depends_on": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "description": {
                    "type": "string"
                  }
                }
              }
            },
            "privileges": {
              "$ref": "#/definitions/privileges"
            },
            "depends_on": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "^aggregate ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "owner": {
              "type": "string"
            },
            "privileges": {
              "$ref": "#/definitions/privileges"
            },
            "sfunc": {
              "type": "string"
            },
            "stype": {
              "type": "string"
            },
            "sspace": {
              "type": "integer"
            },
            "finalfunc": {
              "type": "string"
            },
            "finalfunc_extra": {
              "type": "boolean"
            },
            "initcond": {
              "type": "string"
            },
            "sortop": {
              "type": "string"
            },
            "msfunc": {
              "type": "string"
            },
            "minvfunc": {
              "type": "string"
            },
            "mstype": {
              "type": "string"
            },
            "msspace": {
              "type": "integer"
            },
            "mfinalfunc": {
              "type": "string"
            },
            "mfinalfunc_extra": {
              "type": "boolean"
            },
            "minitcond": {
              "type": "string"
            },
            "kind": {
              "type": "string"
            },
            "combinefunc": {
              "type": "string"
            },
            "serialfunc": {
              "type": "string"
            },
            "deseriafunc": {
              "type": "string"
            },
            "parallel": {
              "type": "string"
            },
            "arguments": {
              "type": "string"
            }
          }
        },
        "^domain ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "owner": {
              "type": "string"
            },
            "type": {
              "type": "string"
            },
            "not_null": {
              "type": "boolean"
            },
            "default": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "number"
                }
              ]
            },
            "check_constraints": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "expression": {
                    "type": "string"
                  },
                  "depends_on": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "^function ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "language": {
              "type": "string"
            },
            "owner": {
              "type": "string"
            },
            "privileges": {
              "$ref": "#/definitions/privileges"
            },
            "returns": {
              "type": "string"
            },
            "source": {
              "type": "string"
            },
            "volatility": {
              "type": "string"
            },
            "strict": {
              "type": "boolean"
            },
            "security_definer": {
              "type": "boolean"
            },
            "description": {
              "type": "string"
            },
            "obj_file": {
              "type": "string"
            },
            "link_symbol": {
              "type": "string"
            },
            "configuration": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "arguments": {
              "type": "string"
            },
            "cost": {
              "type": "integer"
            },
            "rows": {
              "type": "integer"
            },
            "leakproof": {
              "type": "boolean"
            }
          }
        },
        "^sequence ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "description": {
              "type": "string"
            },
            "cache_value": {
              "type": "integer"
            },
            "increment_by": {
              "type": "integer"
            },
            "max_value": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string",
                  "const": "null"
                }
              ]
            },
            "min_value": {
              "oneOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "string",
                  "const": "null"
                }
              ]
            },
            "owner": {
              "type": "string"
            },
            "start_value": {
              "type": "integer"
            },
            "owner_table": {
              "type": "string"
            },
            "owner_column": {
              "type": "string"
            },
            "privileges": {
              "$ref": "#/definitions/privileges"
            },
            "data_type": {
              "type": "string"
            }
          }
        },
        "^type ": {
          "type": "object",
          "additionalProperties": false,
          "description": "5 types: Base Type, Composite, Enum, Domain, Range",
          "properties": {
            "labels": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "owner": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "privileges": {
              "$ref": "#/definitions/privileges"
            },
            "attributes": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "oldname": {
                      "type": "string"
                    }
                  }
                }
              }
            },
            "subtype": {
              "type": "string"
            },
            "oldname": {
              "type": "string"
            },
            "input": {
              "type": "string"
            },
            "output": {
              "type": "string"
            },
            "internallength": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "integer"
                }
              ]
            },
            "alignment": {
              "type": "string"
            },
            "storage": {
              "type": "string"
            },
            "category": {
              "type": "string"
            },
            "subtype_diff": {
              "type": "string"
            },
            "type": {
              "type": "string"
            },
            "not_null": {
              "type": "boolean"
            },
            "default": {
              "type": "string"
            },
            "canonical": {
              "type": "string"
            },
            "receive": {
              "type": "string"
            },
            "send": {
              "type": "string"
            },
            "typmod_in": {
              "type": "string"
            },
            "typmod_out": {
              "type": "string"
            },
            "analyze": {
              "type": "string"
            },
            "delimiter": {
              "type": "string"
            },
            "preferred": {
              "type": "boolean"
            }
          }
        },
        "^view ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "definition": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "owner": {
              "type": "string"
            },
            "depends_on": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "^foreign table ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "owner": {
              "type": "string"
            },
            "description": {
              "type": "string"
            },
            "privileges": {
              "$ref": "#/definitions/privileges"
            },
            "columns": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "type": {
                      "type": "string"
                    }
                  }
                }
              }
            },
            "server": {
              "type": "string"
            },
            "options": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "^collation ": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "lc_collate": {
              "type": "string"
            },
            "lc_ctype": {
              "type": "string"
            },
            "owner": {
              "type": "string"
            },
            "description": {
              "type": "string"
            }
          }
        }
      },
      "properties": {
        "owner": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "privileges": {
          "$ref": "#/definitions/privileges"
        }
      }
    }
  },
  "oneOf": [
    {
      "$ref": "#/definitions/db"
    },
    {
      "$ref": "#/definitions/schema"
    }
  ],
  "title": "JSON schema for Pyrseas yaml files"
}
