44from fastapi import HTTPException
55from fastapi import Path
66
7+ from app .schemas .pgsql import PgSQLCollates
78from app .schemas .pgsql import PgSQLDbAdd
89from app .schemas .pgsql import PgSQLExtension
10+ from app .schemas .pgsql import PgSQLExtensions
911from app .schemas .pgsql import PgSQLPasswd
1012from app .services .socket_client import DevilSocketError
1113from 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
0 commit comments