Skip to content

Commit c3993ed

Browse files
committed
Add endpoints for listing MySQL and PostgreSQL collations and extensions
1 parent dd8b0b7 commit c3993ed

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

app/api/endpoints/mysql.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from fastapi import Path
66

77
from app.schemas.mysql import MySQLAccessAdd
8+
from app.schemas.mysql import MySQLCollate
89
from app.schemas.mysql import MySQLDbAdd
910
from app.schemas.mysql import MySQLPasswd
1011
from app.schemas.mysql import MySQLPrivileges
@@ -203,3 +204,22 @@ async def mysql_list():
203204
raise HTTPException(status_code=400, detail=str(exc)) from exc
204205
except Exception as exc:
205206
raise HTTPException(status_code=400, detail=f"mysql list error: {exc}") from exc
207+
208+
209+
@router.get(
210+
"/collations", summary="List available MySQL collations", tags=["read-only"]
211+
)
212+
async def mysql_collations():
213+
"""
214+
List all available MySQL collations.
215+
216+
Returns a list of all supported MySQL collation values that can be used
217+
when creating databases.
218+
"""
219+
try:
220+
collations = [collation.value for collation in MySQLCollate]
221+
return {"collations": collations}
222+
except Exception as exc:
223+
raise HTTPException(
224+
status_code=500, detail=f"Error retrieving collations: {exc}"
225+
) from exc

app/api/endpoints/pgsql.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
from fastapi import HTTPException
55
from fastapi import Path
66

7+
from app.schemas.pgsql import PgSQLCollates
78
from app.schemas.pgsql import PgSQLDbAdd
89
from app.schemas.pgsql import PgSQLExtension
10+
from app.schemas.pgsql import PgSQLExtensions
911
from app.schemas.pgsql import PgSQLPasswd
1012
from app.services.socket_client import DevilSocketError
1113
from app.services.socket_client import execute_devil_command
@@ -68,7 +70,7 @@ async def pgsql_passwd(data: PgSQLPasswd):
6870

6971

7072
@router.put("/extensions", summary="Enable PostgreSQL extension")
71-
async def pgsql_extensions(data: PgSQLExtension):
73+
async def pgsql_extension(data: PgSQLExtension):
7274
"""
7375
Enable an extension for a PostgreSQL database.
7476
@@ -93,3 +95,41 @@ async def pgsql_list():
9395
return await execute_devil_command(args)
9496
except DevilSocketError as exc:
9597
raise HTTPException(status_code=400, detail=str(exc)) from exc
98+
99+
100+
@router.get(
101+
"/collations", summary="List available PostgreSQL collations", tags=["read-only"]
102+
)
103+
async def pgsql_collations():
104+
"""
105+
List all available PostgreSQL collations.
106+
107+
Returns a list of all supported PostgreSQL collation values that can be used
108+
when creating databases.
109+
"""
110+
try:
111+
collations = [collation.value for collation in PgSQLCollates]
112+
return {"collations": collations}
113+
except Exception as exc:
114+
raise HTTPException(
115+
status_code=500, detail=f"Error retrieving collations: {exc}"
116+
) from exc
117+
118+
119+
@router.get(
120+
"/extensions", summary="List available PostgreSQL extensions", tags=["read-only"]
121+
)
122+
async def pgsql_extensions():
123+
"""
124+
List all available PostgreSQL extensions.
125+
126+
Returns a list of all supported PostgreSQL extension values that can be enabled
127+
for databases.
128+
"""
129+
try:
130+
extensions = [extension.value for extension in PgSQLExtensions]
131+
return {"extensions": extensions}
132+
except Exception as exc:
133+
raise HTTPException(
134+
status_code=500, detail=f"Error retrieving extensions: {exc}"
135+
) from exc

app/schemas/mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
__all__ = [
1212
"MySQLAccessAdd",
13+
"MySQLCollate",
1314
"MySQLDbAdd",
1415
"MySQLPasswd",
1516
"MySQLPrivileges",

app/schemas/pgsql.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
from pydantic import BaseModel
66
from pydantic import Field
77

8-
__all__ = ["PgSQLDbAdd", "PgSQLExtension", "PgSQLExtensions", "PgSQLPasswd"]
8+
__all__ = [
9+
"PgSQLCollates",
10+
"PgSQLDbAdd",
11+
"PgSQLExtension",
12+
"PgSQLExtensions",
13+
"PgSQLPasswd",
14+
]
915

1016

1117
class PgSQLExtensions(str, Enum):

0 commit comments

Comments
 (0)