-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add table metadata model and rpc endpoint
- Loading branch information
Showing
11 changed files
with
157 additions
and
18 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
43 changes: 43 additions & 0 deletions
43
mathesar/migrations/0009_alter_columnmetadata_attnum_and_more.py
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,43 @@ | ||
# Generated by Django 4.2.11 on 2024-06-27 20:00 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('mathesar', '0008_add_metadata_models'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='columnmetadata', | ||
name='attnum', | ||
field=models.SmallIntegerField(), | ||
), | ||
migrations.AlterField( | ||
model_name='columnmetadata', | ||
name='table_oid', | ||
field=models.PositiveBigIntegerField(), | ||
), | ||
migrations.CreateModel( | ||
name='TableMetaData', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('schema_oid', models.PositiveBigIntegerField()), | ||
('table_oid', models.PositiveBigIntegerField()), | ||
('import_verified', models.BooleanField(default=False)), | ||
('column_order', models.JSONField(default=list)), | ||
('preview_customized', models.BooleanField(default=False)), | ||
('preview_template', models.CharField(blank=True, max_length=255)), | ||
('database', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='mathesar.database')), | ||
], | ||
), | ||
migrations.AddConstraint( | ||
model_name='tablemetadata', | ||
constraint=models.UniqueConstraint(fields=('database', 'schema_oid', 'table_oid'), name='unique_table_metadata'), | ||
), | ||
] |
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 @@ | ||
from .base import * # noqa |
File renamed without changes.
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,66 @@ | ||
""" | ||
Classes and functions exposed to the RPC endpoint for managing table metadata. | ||
""" | ||
from typing import Optional, TypedDict | ||
|
||
from modernrpc.core import rpc_method | ||
from modernrpc.auth.basic import http_basic_auth_login_required | ||
|
||
from mathesar.rpc.exceptions.handlers import handle_rpc_exceptions | ||
from mathesar.utils.tables import get_table_meta_data | ||
|
||
|
||
class TableMetaData(TypedDict): | ||
""" | ||
Metadata for a table in a database. | ||
Only the `database`, `schema_oid`, and `table_oid` keys are required. | ||
Attributes: | ||
database_id: The Django id of the database containing the table. | ||
schema_oid: The OID of the schema containing the table. | ||
table_oid: The OID of the table in the database. | ||
import_verified: Specifies whether a file has been successfully imported into a table. | ||
column_order: The order in which columns of a table are displayed. | ||
preview_customized: Specifies whether the preview has been customized. | ||
preview_template: Preview template for a referent column. | ||
""" | ||
database_id: int | ||
schema_oid: int | ||
table_oid: int | ||
import_verified: Optional[bool] | ||
column_order: Optional[list[int]] | ||
preview_customized: Optional[bool] | ||
preview_template: Optional[str] | ||
|
||
@classmethod | ||
def from_model(cls, model): | ||
return cls( | ||
database_id=model.database.id, | ||
schema_oid=model.schema_oid, | ||
table_oid=model.table_oid, | ||
import_verified=model.import_verified, | ||
column_order=model.column_order, | ||
preview_customized=model.preview_customized, | ||
preview_template=model.preview_template, | ||
) | ||
|
||
|
||
@rpc_method(name="tables.metadata.get") | ||
@http_basic_auth_login_required | ||
@handle_rpc_exceptions | ||
def list(*, schema_oid: int, database_id: int, **kwargs) -> list[TableMetaData]: | ||
""" | ||
List metadata associated with tables for a schema. | ||
Args: | ||
schema_oid: Identity of the schema in the user's database. | ||
database_id: The Django id of the database containing the table. | ||
Returns: | ||
Metadata object for a given table oid. | ||
""" | ||
table_meta_data = get_table_meta_data(schema_oid, database_id) | ||
return [ | ||
TableMetaData.from_model(model) for model in table_meta_data | ||
] |
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
Empty file.
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