|
1 | | -# SPDX-FileCopyrightText: 2025 Adel Memariani <https://github.com/adelmemariani> © Otto-von-Guericke-Universität Magdeburg |
2 | | -# SPDX-FileCopyrightText: 2025 Adel Memariani <https://github.com/adelmemariani> © Otto-von-Guericke-Universität Magdeburg |
3 | | -# SPDX-FileCopyrightText: 2025 Christian Winger <https://github.com/wingechr> © Öko-Institut e.V. |
4 | | -# SPDX-FileCopyrightText: 2025 Eike Broda <https://github.com/ebroda> |
5 | | -# SPDX-FileCopyrightText: 2025 Johann Wagner <https://github.com/johannwagner> © Otto-von-Guericke-Universität Magdeburg |
6 | | -# SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut |
7 | | -# SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut |
8 | | -# SPDX-FileCopyrightText: 2025 Martin Glauer <https://github.com/MGlauer> © Otto-von-Guericke-Universität Magdeburg |
9 | | -# SPDX-FileCopyrightText: 2025 Martin Glauer <https://github.com/MGlauer> © Otto-von-Guericke-Universität Magdeburg |
10 | | -# SPDX-FileCopyrightText: 2025 Martin Glauer <https://github.com/MGlauer> © Otto-von-Guericke-Universität Magdeburg |
11 | | -# SPDX-FileCopyrightText: 2025 Christian Winger <https://github.com/wingechr> © Öko-Institut e.V. |
12 | | -# SPDX-FileCopyrightText: 2025 Christian Hofmann <https://github.com/christian-rli> © Reiner Lemoine Institut |
13 | | -# SPDX-FileCopyrightText: 2025 chrwm <https://github.com/chrwm> © Reiner Lemoine Institut |
14 | | -# SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut |
15 | | -# SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut |
16 | | -# SPDX-FileCopyrightText: 2025 user <https://github.com/Darynarli> © Reiner Lemoine Institut |
17 | | -# SPDX-FileCopyrightText: 2025 Christian Winger <https://github.com/wingechr> © Öko-Institut e.V. |
| 1 | +# SPDX-FileCopyrightText: 2025 Adel Memariani <https://github.com/adelmemariani> © Otto-von-Guericke-Universität Magdeburg # noqa: E501 |
| 2 | +# SPDX-FileCopyrightText: 2025 Adel Memariani <https://github.com/adelmemariani> © Otto-von-Guericke-Universität Magdeburg # noqa: E501 |
| 3 | +# SPDX-FileCopyrightText: 2025 Christian Winger <https://github.com/wingechr> © Öko-Institut e.V. # noqa: E501 |
| 4 | +# SPDX-FileCopyrightText: 2025 Eike Broda <https://github.com/ebroda> # noqa: E501 |
| 5 | +# SPDX-FileCopyrightText: 2025 Johann Wagner <https://github.com/johannwagner> © Otto-von-Guericke-Universität Magdeburg # noqa: E501 |
| 6 | +# SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut # noqa: E501 |
| 7 | +# SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut # noqa: E501 |
| 8 | +# SPDX-FileCopyrightText: 2025 Martin Glauer <https://github.com/MGlauer> © Otto-von-Guericke-Universität Magdeburg # noqa: E501 |
| 9 | +# SPDX-FileCopyrightText: 2025 Martin Glauer <https://github.com/MGlauer> © Otto-von-Guericke-Universität Magdeburg # noqa: E501 |
| 10 | +# SPDX-FileCopyrightText: 2025 Martin Glauer <https://github.com/MGlauer> © Otto-von-Guericke-Universität Magdeburg # noqa: E501 |
| 11 | +# SPDX-FileCopyrightText: 2025 Christian Winger <https://github.com/wingechr> © Öko-Institut e.V. # noqa: E501 |
| 12 | +# SPDX-FileCopyrightText: 2025 Christian Hofmann <https://github.com/christian-rli> © Reiner Lemoine Institut # noqa: E501 |
| 13 | +# SPDX-FileCopyrightText: 2025 chrwm <https://github.com/chrwm> © Reiner Lemoine Institut # noqa: E501 |
| 14 | +# SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut # noqa: E501 |
| 15 | +# SPDX-FileCopyrightText: 2025 Jonas Huber <https://github.com/jh-RLI> © Reiner Lemoine Institut # noqa: E501 |
| 16 | +# SPDX-FileCopyrightText: 2025 user <https://github.com/Darynarli> © Reiner Lemoine Institut # noqa: E501 |
| 17 | +# SPDX-FileCopyrightText: 2025 Christian Winger <https://github.com/wingechr> © Öko-Institut e.V. # noqa: E501 |
18 | 18 | # |
19 | 19 | # SPDX-License-Identifier: AGPL-3.0-or-later |
20 | 20 |
|
@@ -1749,3 +1749,31 @@ def post(self, request): |
1749 | 1749 | # ) |
1750 | 1750 |
|
1751 | 1751 | # return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
| 1752 | + |
| 1753 | + |
| 1754 | +class TableSize(APIView): |
| 1755 | + """ |
| 1756 | + GET /api/v0/db/table-sizes/?schema=<schema>&table=<table> |
| 1757 | + - schema+table -> single relation (detailed) |
| 1758 | + - schema only -> all tables in that schema (whitelisted) |
| 1759 | + - none -> all tables in whitelist |
| 1760 | + """ |
| 1761 | + |
| 1762 | + @api_exception |
| 1763 | + def get(self, request): |
| 1764 | + schema = request.query_params.get("schema") |
| 1765 | + table = request.query_params.get("table") |
| 1766 | + |
| 1767 | + allowed = schema_whitelist # reuse existing whitelist |
| 1768 | + |
| 1769 | + if schema and table: |
| 1770 | + if schema not in allowed: |
| 1771 | + raise APIError(f"Schema '{schema}' is not allowed.", status=403) |
| 1772 | + data = actions.get_single_table_size(schema, table, allowed) |
| 1773 | + if not data: |
| 1774 | + raise APIError(f"Relation {schema}.{table} not found.", status=404) |
| 1775 | + return Response(data) |
| 1776 | + |
| 1777 | + # list mode (schema optional) |
| 1778 | + data = actions.list_table_sizes(allowed_schemas=allowed, schema=schema) |
| 1779 | + return Response(data, status=status.HTTP_200_OK) |
0 commit comments