{
    "$schema": "https://json-schema.org/draft-07/schema",
    "$id": "https://yndigoblue.com/velocity.json",
    "title": "YndigoBlue Velocity Schema Definitions",
    "description": "Lays out the JSON schema for defining Velocity Relataional Database Schema Documents.",
    "definitions": {
        "Database": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                },
                "schemas": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Schema"
                    }
                }
            },
            "required": [
                "name",
                "schemas"
            ],
            "title": "Database"
        },
        "Schema": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                },
                "tables": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Table"
                    }
                },
                "views": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/View"
                    }
                }
            },
            "required": [
                "name",
                "tables"
            ],
            "title": "Schema"
        },
        "Table": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                },
                "schemaUpdate": {
                    "type": "boolean"
                },
                "columns": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Column"
                    }
                },
                "constraints": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Constraint"
                    }
                },
                "spatial": {
                    "$ref": "#/definitions/Spatial"
                },
                "fullText": {
                    "$ref": "#/definitions/FullText"
                },
                "indexes": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Index"
                    }
                }
            },
            "required": [
                "columns",
                "name"
            ],
            "title": "Table"
        },
        "Column": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                },
                "type": {
                    "$ref": "#/definitions/ColumnType"
                },
                "notNull": {
                    "type": "boolean"
                },
                "autogenerate": {
                    "type": "boolean"
                },
                "size": {
                    "type": "integer"
                },
                "precision": {
                    "type": "integer"
                },
                "scale": {
                    "type": "integer"
                },
                "schemaUpdate": {
                    "type": "boolean"
                },
                "columnUpdate": {
                    "type": "boolean"
                },
                "existingRowValue": {
                    "type": "string"
                },
                "existingRowType": {
                    "$ref": "#/definitions/DefaultType"
                }
            },
            "required": [
                "name",
                "type"
            ],
            "title": "Column"
        },
        "Constraint": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "type": {
                    "$ref": "#/definitions/ConstraintType"
                },
                "name": {
                    "type": "string"
                },
                "schemaUpdate": {
                    "type": "boolean"
                },
                "primaryKey": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "keyColumns": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        }
                    }
                },
                "check": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "checkParts": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/CheckPart"
                            }
                        }
                    }
                },
                "default": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "defaultColumn": {
                            "type": "string"
                        },
                        "defaultType": {
                            "$ref": "#/definitions/DefaultType"
                        },
                        "defaultValue": {
                            "type": "string"
                        }
                    }
                },
                "foreignKey": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "deleteRule": {
                            "$ref": "#/definitions/DeleteRule"
                        },
                        "updateRule": {
                            "$ref": "#/definitions/UpdateRule"
                        },
                        "sourceColumns": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        },
                        "lookupSchema": {
                            "type": "string"
                        },
                        "lookupTable": {
                            "type": "string"
                        },
                        "lookupColumns": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        }
                    }
                },
                "unique": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "uniqueColumns": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        }
                    }
                }
            },
            "required": [
                "type"
            ],
            "title": "Constraint"
        },
        "CheckPart": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "type": {
                    "$ref": "#/definitions/CheckPartType"
                },
                "value": {
                    "type": "string"
                }
            },
            "required": [
                "type",
                "value"
            ],
            "title": "CheckPart"
        },
        "FullText": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                },
                "schemaUpdate": {
                    "type": "boolean"
                },
                "columns": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            },
            "required": [
                "columns",
                "name"
            ],
            "title": "FullText"
        },
        "Index": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                },
                "schemaUpdate": {
                    "type": "boolean"
                },
                "indexColumns": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/IndexColumn"
                    }
                }
            },
            "required": [
                "indexColumns",
                "name"
            ],
            "title": "Index"
        },
        "IndexColumn": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                },
                "order": {
                    "$ref": "#/definitions/OrderType"
                }
            },
            "required": [
                "name",
                "order"
            ],
            "title": "IndexColumn"
        },
        "Spatial": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                },
                "schemaUpdate": {
                    "type": "boolean"
                },
                "column": {
                    "type": "string"
                },
                "xmin": {
                    "type": "number"
                },
                "xmax": {
                    "type": "number"
                },
                "ymin": {
                    "type": "number"
                },
                "ymax": {
                    "type": "number"
                },
                "smallGridSize": {
                    "type": "number"
                },
                "mediumGridSize": {
                    "type": "number"
                },
                "largeGridSize": {
                    "type": "number"
                }
            },
            "required": [
                "column",
                "largeGridSize",
                "mediumGridSize",
                "name",
                "smallGridSize",
                "xmax",
                "xmin",
                "ymax",
                "ymin"
            ],
            "title": "Spatial"
        },
        "CheckPartType": {
            "type": "string",
            "enum": [
                "column",
                "operator",
                "function",
                "number",
                "string",
                "date",
                "datetime",
                "timestamp",
                "snippet"
            ],
            "title": "CheckPartType"
        },
        "ConstraintType": {
            "type": "string",
            "enum": [
                "primarykey",
                "check",
                "default",
                "foreignkey",
                "unique"
            ],
            "title": "ConstraintType"
        },
        "ColumnType": {
            "type": "string",
            "enum": [
                "blob",
                "boolean",
                "byte",
                "char",
                "clob",
                "date",
                "datetime",
                "decimal",
                "double",
                "float",
                "geometry",
                "geography",
                "integer",
                "long",
                "short",
                "varchar",
                "timestamp"
            ],
            "title": "ColumnType"
        },
        "OrderType": {
            "type": "string",
            "enum": [
                "ascending",
                "descending"
            ],
            "title": "OrderType"
        },
        "DeleteRule": {
            "type": "string",
            "enum": [
                "cascade",
                "noaction",
                "restrict",
                "setnull",
                "setdefault"
            ],
            "title": "DeleteRule"
        },
        "UpdateRule": {
            "type": "string",
            "enum": [
                "cascade",
                "noaction",
                "restrict",
                "setnull",
                "setdefault"
            ],
            "title": "UpdateRule"
        },
        "DefaultType": {
            "type": "string",
            "enum": [
                "number",
                "string",
                "date",
                "datetime",
                "timestamp",
                "boolean",
                "function"
            ],
            "title": "DefaultType"
        },
        "View": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                },
                "schemaUpdate": {
                    "type": "boolean"
                },
                "type": {
                    "$ref": "#/definitions/ViewType"
                },
                "definition": {
                    "type": "string"
                },
                "content": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            },
            "required": [
                "name",
                "type"
            ],
            "title": "View"
        },
        "ViewType": {
            "type": "string",
            "enum": [
                "sql",
                "code"
            ],
            "title": "ViewType"
        }
    }
}