Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get imports working again #3819

Merged
merged 12 commits into from
Sep 16, 2024
4 changes: 2 additions & 2 deletions mathesar/rpc/tables/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def from_model(cls, model):
id=model.id,
database_id=model.database.id,
table_oid=model.table_oid,
data_file_id=model.data_file.id if model.data_file is not None else None,
data_file_id=model.data_file_id,
import_verified=model.import_verified,
column_order=model.column_order,
record_summary_customized=model.record_summary_customized,
Expand Down Expand Up @@ -69,7 +69,7 @@ class TableMetaDataBlob(TypedDict):
@classmethod
def from_model(cls, model):
return cls(
data_file_id=model.data_file.id if model.data_file is not None else None,
data_file_id=model.data_file_id,
import_verified=model.import_verified,
column_order=model.column_order,
record_summary_customized=model.record_summary_customized,
Expand Down
5 changes: 1 addition & 4 deletions mathesar/utils/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from db.tables.operations.infer_types import infer_table_column_types
from mathesar.database.base import create_mathesar_engine
from mathesar.imports.base import create_table_from_data_file
from mathesar.models.deprecated import Table, DataFile
from mathesar.models.deprecated import Table
from mathesar.models.base import Database, TableMetaData
from mathesar.state.django import reflect_columns_from_tables
from mathesar.state import get_cached_metadata
Expand Down Expand Up @@ -107,9 +107,6 @@ def get_table_meta_data(table_oid, database_id):
def set_table_meta_data(table_oid, metadata, database_id):
return TableMetaData.objects.update_or_create(
database=Database.objects.get(id=database_id),
data_file=DataFile.objects.get(
id=metadata.pop('data_file_id')
) if metadata.get('data_file_id') is not None else None,
table_oid=table_oid,
defaults=metadata,
)[0]
2 changes: 1 addition & 1 deletion mathesar_ui/src/api/rpc/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type TimeFormat = '24hr' | '12hr' | '24hrLong' | '12hrLong';
*
* [1]: https://www.postgresql.org/docs/current/datatype-numeric.html
*/
interface ColumnTypeOptions {
export interface ColumnTypeOptions {
/**
* For numeric types, the number of significant digits. For date/time types,
* the number of fractional digits.
Expand Down
16 changes: 16 additions & 0 deletions mathesar_ui/src/api/rpc/data_modeling.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

// eslint-disable-next-line @typescript-eslint/naming-convention
export const data_modeling = {
/**
* Returns a record where keys are stringified column attnums and values are
* postgresql types
*/
suggest_types: rpcMethodTypeContainer<
{
database_id: number;
table_oid: number;
},
Record<string, string>
>(),
};
6 changes: 4 additions & 2 deletions mathesar_ui/src/api/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { buildRpcApi } from '@mathesar/packages/json-rpc-client-builder';
import { collaborators } from './collaborators';
import { columns } from './columns';
import { constraints } from './constraints';
import { data_modeling } from './data_modeling';
import { databases } from './databases';
import { records } from './records';
import { roles } from './roles';
Expand All @@ -18,13 +19,14 @@ export const api = buildRpcApi({
getHeaders: () => ({ 'X-CSRFToken': Cookies.get('csrftoken') }),
methodTree: {
collaborators,
columns,
constraints,
data_modeling,
databases,
records,
roles,
schemas,
servers,
tables,
columns,
constraints,
},
});
68 changes: 67 additions & 1 deletion mathesar_ui/src/api/rpc/tables.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { RecursivePartial } from '@mathesar/component-library';
import { rpcMethodTypeContainer } from '@mathesar/packages/json-rpc-client-builder';

import type { ColumnTypeOptions } from './columns';

export interface RawTable {
oid: number;
name: string;
Expand All @@ -9,6 +12,16 @@ export interface RawTable {
}

interface TableMetadata {
/** The id of the data file used during import while creating the table */
data_file_id: number | null;
/**
* When `true` or `null`, the table has been imported from a data file and the
* data has been verified to be correct, with the data types customized by the
* user.
*
* When false, the table still requires import verification before it can be
* viewed in the table page.
*/
import_verified: boolean | null;
column_order: number[] | null;
record_summary_customized: boolean | null;
Expand Down Expand Up @@ -62,6 +75,17 @@ export interface JoinableTablesResult {
>;
}

/**
* The parameters needed for one column in order to generate an import preview.
*/
export interface ColumnPreviewSpec {
/** Column attnum */
id: number;
/** The new type to be applied to the column */
type?: string;
type_options?: ColumnTypeOptions | null;
}

export const tables = {
list: rpcMethodTypeContainer<
{
Expand Down Expand Up @@ -107,7 +131,25 @@ export const tables = {
/** TODO */
constraint_data_list?: unknown;
},
number
{
oid: number;
name: string;
}
>(),

/** Returns the oid of the table created */
import: rpcMethodTypeContainer<
{
database_id: number;
schema_oid: number;
table_name?: string;
comment?: string;
data_file_id: number;
},
{
oid: number;
name: string;
}
>(),

patch: rpcMethodTypeContainer<
Expand Down Expand Up @@ -139,4 +181,28 @@ export const tables = {
},
JoinableTablesResult
>(),

get_import_preview: rpcMethodTypeContainer<
{
database_id: number;
table_oid: number;
columns: ColumnPreviewSpec[];
/** The upper limit for the number of records to return. Defaults to 20 */
limit?: number;
},
Record<string, unknown>[]
>(),

metadata: {
list: rpcMethodTypeContainer<{ database_id: number }, TableMetadata[]>(),

set: rpcMethodTypeContainer<
{
database_id: number;
table_oid: number;
metadata: RecursivePartial<TableMetadata>;
},
void
>(),
},
};
4 changes: 2 additions & 2 deletions mathesar_ui/src/components/AppHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
return;
}
isCreatingNewEmptyTable = true;
const tableOid = await createTable(database, schema, {});
const table = await createTable({ database, schema });
isCreatingNewEmptyTable = false;
router.goto(getTablePageUrl(database.id, schema.oid, tableOid), false);
router.goto(getTablePageUrl(database.id, schema.oid, table.oid), false);
}
</script>

Expand Down
Loading
Loading