-
-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'architectural_overhaul' into col_delete_func_take2
- Loading branch information
Showing
13 changed files
with
197 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
MATHESAR_PREFIX = "mathesar_" | ||
ID = "id" | ||
ID_ORIGINAL = "id_original" | ||
INFERENCE_SCHEMA = f"{MATHESAR_PREFIX}inference_schema" | ||
COLUMN_NAME_TEMPLATE = 'Column ' # auto generated column name 'Column 1' (no undescore) | ||
MSAR_PUBLIC = 'msar' | ||
MSAR_PRIVAT = f"__{MSAR_PUBLIC}" | ||
MSAR_VIEWS = f"{MSAR_PUBLIC}_views" | ||
|
||
MATHESAR_PREFIX = "mathesar_" | ||
MSAR_PUBLIC_SCHEMA = 'msar' | ||
MSAR_PRIVATE_SCHEMA = f"__{MSAR_PUBLIC_SCHEMA}" | ||
TYPES_SCHEMA = f"{MATHESAR_PREFIX}types" | ||
INFERENCE_SCHEMA = f"{MATHESAR_PREFIX}inference_schema" | ||
VIEWS_SCHEMA = f"{MSAR_PUBLIC_SCHEMA}_views" | ||
|
||
INTERNAL_SCHEMAS = { | ||
TYPES_SCHEMA, | ||
MSAR_PUBLIC_SCHEMA, | ||
MSAR_PRIVATE_SCHEMA, | ||
VIEWS_SCHEMA, | ||
INFERENCE_SCHEMA | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" | ||
Classes and functions exposed to the RPC endpoint for managing schemas. | ||
""" | ||
from typing import Optional, TypedDict | ||
|
||
from modernrpc.core import rpc_method, REQUEST_KEY | ||
from modernrpc.auth.basic import http_basic_auth_login_required | ||
|
||
from db.constants import INTERNAL_SCHEMAS | ||
from db.schemas.operations.select import get_schemas | ||
from mathesar.rpc.exceptions.handlers import handle_rpc_exceptions | ||
from mathesar.rpc.utils import connect | ||
|
||
|
||
class SchemaInfo(TypedDict): | ||
""" | ||
Information about a schema | ||
Attributes: | ||
oid: The OID of the schema | ||
name: The name of the schema | ||
description: A description of the schema | ||
table_count: The number of tables in the schema | ||
exploration_count: The number of explorations in the schema | ||
""" | ||
oid: int | ||
name: str | ||
description: Optional[str] | ||
table_count: int | ||
exploration_count: int | ||
|
||
|
||
@rpc_method(name="schemas.list") | ||
@http_basic_auth_login_required | ||
@handle_rpc_exceptions | ||
def list_(*, database_id: int, **kwargs) -> list[SchemaInfo]: | ||
""" | ||
List information about schemas in a database. Exposed as `list`. | ||
Args: | ||
database_id: The Django id of the database containing the table. | ||
Returns: | ||
A list of schema details | ||
""" | ||
user = kwargs.get(REQUEST_KEY).user | ||
with connect(database_id, user) as conn: | ||
schemas = get_schemas(conn) | ||
|
||
user_defined_schemas = [s for s in schemas if s['name'] not in INTERNAL_SCHEMAS] | ||
|
||
# TODO_FOR_BETA: join exploration count from internal DB here after we've | ||
# refactored the models so that each exploration is associated with a schema | ||
# (by oid) in a specific database. | ||
return [{**s, "exploration_count": 0} for s in user_defined_schemas] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters