Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 80 additions & 58 deletions docs/configuration/schema.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,84 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/gitmobkab/copia/main/docs/configuration/schema.json",
"title": "Copia Configuration",
"description": "Configuration schema for copia — https://gitmobkab.github.io/copia/configuration",
"type": "object",
"properties": {
"profiles": {
"type": "object",
"description": "Named database connection profiles.",
"additionalProperties": {
"$ref": "#/$defs/Profile"
}
}
},
"additionalProperties": false,
"$defs": {
"Profile": {
"type": "object",
"description": "A database connection profile.",
"required": ["adapter", "host", "port", "database", "user"],
"additionalProperties": false,
"properties": {
"adapter": {
"type": "string",
"description": "The database adapter to use.",
"enum": ["mysql"],
"enumDescriptions": [
"MySQL / MariaDB"
]
},
"host": {
"type": "string",
"description": "Database host. Accepts a hostname, IPv4, or IPv6 address.",
"examples": ["localhost", "127.0.0.1", "db.example.com"]
},
"port": {
"type": "integer",
"description": "Database port. Must be between 1 and 65535.",
"minimum": 1,
"maximum": 65535,
"examples": [3306]
},
"database": {
"type": "string",
"description": "Target database name. Must be non-empty and ASCII only.",
"minLength": 1
},
"user": {
"type": "string",
"description": "Database user. Must be non-empty and ASCII only.",
"minLength": 1
},
"password": {
"type": "string",
"description": "Database password. Optional — defaults to empty string.",
"default": ""
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/gitmobkab/copia/main/docs/configuration/schema.json",
"title": "Copia Configuration",
"description": "Configuration schema for copia - https://gitmobkab.github.io/copia/configuration",
"type": "object",
"properties": {
"profiles": {
"type": "object",
"description": "Named database connection profiles.",
"additionalProperties": {
"$ref": "#/$defs/Profile"
}
}
},
"$defs": {
"Profile": {
"additionalProperties": false,
"properties": {
"adapter": {
"description": "The copia Adapter to use",
"enum": [
"mysql",
"postgres"
],
"title": "Adapter",
"type": "string",
"enumDescriptions": [
"MySQL / MariaDB",
"PostgreSQL"
]
},
"host": {
"anyOf": [
{
"format": "ipvanyaddress",
"type": "string"
},
{
"minLength": 1,
"type": "string"
}
],
"description": "The database hostname",
"title": "Host"
},
"port": {
"description": "The Database Port",
"maximum": 65535,
"minimum": 1,
"title": "Port",
"type": "integer"
},
"database": {
"description": "The Database Port",
"minLength": 1,
"title": "Database",
"type": "string"
},
"user": {
"description": "The Database Username",
"minLength": 1,
"title": "User",
"type": "string"
},
"password": {
"default": "",
"description": "The Database Password",
"title": "Password",
"type": "string"
}
},
"required": [
"adapter",
"host",
"port",
"database",
"user"
],
"title": "Profile",
"type": "object"
}
}
}
}
}
33 changes: 33 additions & 0 deletions scripts/config_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json
from copia.cli.config import Profile

def generate_schema() -> dict:
profile_schema = Profile.model_json_schema()

# inject enumDescriptions manually since it's non-standard
if "properties" in profile_schema:
adapter = profile_schema["properties"].get("adapter", {})
if "enum" in adapter:
adapter["enumDescriptions"] = ["MySQL / MariaDB", "PostgreSQL"]

return {
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/gitmobkab/copia/main/docs/configuration/schema.json",
"title": "Copia Configuration",
"description": "Configuration schema for copia - https://gitmobkab.github.io/copia/configuration",
"type": "object",
"properties": {
"profiles": {
"type": "object",
"description": "Named database connection profiles.",
"additionalProperties": {"$ref": "#/$defs/Profile"},
}
},
"$defs": {"Profile": profile_schema},
}

if __name__ == "__main__":
schema = generate_schema()
output = "docs/configuration/schema.json"
with open(output, "w") as f:
json.dump(schema, f, indent=4)
13 changes: 7 additions & 6 deletions src/copia/cli/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
Port = Annotated[int, Field(
ge= PORT_MIN_VAL,
le= PORT_MAX_VAL,
strict=True
strict=True,
description="The Database Port"
)]

class Profile(BaseModel):
model_config = ConfigDict(extra="forbid")

adapter: Adapter
host: Union[IPvAnyAddress, NotEmptyStr]
adapter: Adapter = Field(description="The copia Adapter to use")
host: Union[IPvAnyAddress, NotEmptyStr] = Field(description="The database hostname")
port: Port
database: NotEmptyStr
user: NotEmptyStr
password: str = ""
database: NotEmptyStr = Field(description="The Database Port")
user: NotEmptyStr = Field(description="The Database Username")
password: str = Field("", description="The Database Password")


def __str__(self) -> str:
Expand Down
Loading