diff --git a/db/columns.py b/db/columns.py index 48f0013fd8..b07163d9fb 100644 --- a/db/columns.py +++ b/db/columns.py @@ -32,7 +32,6 @@ def get_column_info_for_table(table, conn): }, "nullable": , "primary_key": , - "valid_target_types": [, , ..., ] "default": {"value": , "is_dynamic": }, "has_dependents": , "current_role_priv": [, , ...], diff --git a/db/sql/05_msar.sql b/db/sql/05_msar.sql index 63bddf85c4..d3fce4d79c 100644 --- a/db/sql/05_msar.sql +++ b/db/sql/05_msar.sql @@ -857,34 +857,6 @@ SELECT nullif( $$ LANGUAGE SQL RETURNS NULL ON NULL INPUT; -CREATE OR REPLACE FUNCTION msar.get_valid_target_type_strings(typ_id regtype) RETURNS jsonb AS $$/* -Given a source type, return the target types for which Mathesar provides a casting function. - -Args: - typ_id: The type we're casting from. -*/ - -SELECT jsonb_agg(prorettype::regtype::text) -FROM pg_proc -WHERE - pronamespace=msar.get_schema_oid('msar') - AND proargtypes[0]= - CASE WHEN typ_id = ANY(ARRAY['smallint', 'integer', 'mathesar_types.mathesar_money']::regtype[]) - THEN 'numeric'::regtype - WHEN typ_id = ANY(ARRAY['"char"', 'character', 'character varying', 'mathesar_types.email', 'mathesar_types.uri']::regtype[]) - THEN 'text'::regtype - WHEN typ_id = ANY(ARRAY['mathesar_types.mathesar_json_array', 'mathesar_types.mathesar_json_object']::regtype[]) - THEN 'jsonb'::regtype - WHEN typ_id = 'time without time zone'::regtype - THEN 'time with time zone'::regtype - WHEN typ_id = 'timestamp without time zone'::regtype - THEN 'timestamp with time zone'::regtype - ELSE typ_id - END - AND left(proname, 5) = 'cast_'; -$$ LANGUAGE SQL RETURNS NULL ON NULL INPUT; - - CREATE OR REPLACE FUNCTION msar.has_dependents(rel_id oid, att_id smallint) RETURNS boolean AS $$/* Return a boolean according to whether the column identified by the given oid, attnum pair is referenced (i.e., would dropping that column require CASCADE?). @@ -989,8 +961,7 @@ Each returned JSON object in the array will have the form: "default": {"value": , "is_dynamic": }, "has_dependents": , "description": , - "current_role_priv": [, , ...], - "valid_target_types": [, , ...] + "current_role_priv": [, , ...] } The `type_options` object is described in the docstring of `msar.get_type_options`. The `default` @@ -1009,8 +980,7 @@ SELECT jsonb_agg( 'default', msar.describe_column_default(tab_id, attnum), 'has_dependents', msar.has_dependents(tab_id, attnum), 'description', msar.col_description(tab_id, attnum), - 'current_role_priv', msar.list_column_privileges_for_current_role(tab_id, attnum), - 'valid_target_types', msar.get_valid_target_type_strings(atttypid) + 'current_role_priv', msar.list_column_privileges_for_current_role(tab_id, attnum) ) ) FROM pg_attribute pga diff --git a/db/sql/test_sql_functions.sql b/db/sql/test_sql_functions.sql index 49554b98a4..1a9781d029 100644 --- a/db/sql/test_sql_functions.sql +++ b/db/sql/test_sql_functions.sql @@ -2834,48 +2834,6 @@ END; $$ LANGUAGE plpgsql; -CREATE OR REPLACE FUNCTION test_get_valid_target_type_strings() RETURNS SETOF TEXT AS $$ -DECLARE - target_type_strings jsonb; -BEGIN - target_type_strings = msar.get_valid_target_type_strings('text'); - RETURN NEXT is(jsonb_array_length(target_type_strings), 28); - RETURN NEXT ok( - target_type_strings @> jsonb_build_array( - 'real', 'double precision', 'mathesar_types.email', 'smallint', 'boolean', 'bigint', - 'integer', 'interval', 'time without time zone', 'time with time zone', - 'timestamp with time zone', 'timestamp without time zone', 'date', - 'mathesar_types.mathesar_money', 'money', 'mathesar_types.multicurrency_money', - 'character varying', 'character', '"char"', 'text', 'name', 'mathesar_types.uri', 'numeric', - 'jsonb', 'mathesar_types.mathesar_json_array', 'mathesar_types.mathesar_json_object', 'json', 'uuid' - ), - 'containment plus length checks order-independent equality' - ); - target_type_strings = msar.get_valid_target_type_strings('text'::regtype::oid); - RETURN NEXT is(jsonb_array_length(target_type_strings), 28); - RETURN NEXT ok( - target_type_strings @> jsonb_build_array( - 'real', 'double precision', 'mathesar_types.email', 'smallint', 'boolean', 'bigint', - 'integer', 'interval', 'time without time zone', 'time with time zone', - 'timestamp with time zone', 'timestamp without time zone', 'date', - 'mathesar_types.mathesar_money', 'money', 'mathesar_types.multicurrency_money', - 'character varying', 'character', '"char"', 'text', 'name', 'mathesar_types.uri', 'numeric', - 'jsonb', 'mathesar_types.mathesar_json_array', 'mathesar_types.mathesar_json_object', 'json', 'uuid' - ), - 'containment plus length checks order-independent equality' - ); - target_type_strings = msar.get_valid_target_type_strings('interval'); - RETURN NEXT is(jsonb_array_length(target_type_strings), 6); - RETURN NEXT ok( - target_type_strings @> jsonb_build_array( - 'interval', 'character varying', 'character', '"char"', 'text', 'name' - ), - 'containment plus length checks order-independent equality' - ); -END; -$$ LANGUAGE plpgsql; - - CREATE OR REPLACE FUNCTION test_has_dependents() RETURNS SETOF TEXT AS $$ BEGIN PERFORM __setup_extract_fkey_cols(); @@ -2907,8 +2865,8 @@ $$ LANGUAGE plpgsql; CREATE OR REPLACE FUNCTION test_get_column_info() RETURNS SETOF TEXT AS $$/* -This test doesn't inspect the contents of the current_role_priv or valid_target_types arrays, since -the functions that generate those contents are tested elsewhere. We just make sure the arrays exist, +This test doesn't inspect the contents of the current_role_priv array, since +the functions that generate those contents are tested elsewhere. We just make sure the array exist, and are non-empty. All other contents of the returned jsonb are tested. */ DECLARE @@ -2920,7 +2878,7 @@ BEGIN -- Column 1 RETURN NEXT is( - (col_info -> 0) - ARRAY['current_role_priv', 'valid_target_types'], + (col_info -> 0) - ARRAY['current_role_priv'], $j${ "id": 1, "name": "id", "type": "integer", "default": {"value": "identity", "is_dynamic": true}, @@ -2929,14 +2887,13 @@ BEGIN }$j$ ); RETURN NEXT ok( - jsonb_array_length(col_info -> 0 -> 'current_role_priv') > 0 - AND jsonb_array_length(col_info -> 0 -> 'valid_target_types') > 0, - 'current_role_priv and valid_target_types should be non-empty jsonb arrays' + jsonb_array_length(col_info -> 0 -> 'current_role_priv') > 0, + 'current_role_priv should be a non-empty jsonb array' ); -- Column 2 RETURN NEXT is( - (col_info -> 1) - ARRAY['current_role_priv', 'valid_target_types'], + (col_info -> 1) - ARRAY['current_role_priv'], $j${ "id": 2, "name": "num_plain", "type": "numeric", "default": null, "nullable": false, "description": null, "primary_key": false, "type_options": {"scale": null, "precision": null}, @@ -2944,14 +2901,13 @@ BEGIN }$j$ ); RETURN NEXT ok( - jsonb_array_length(col_info -> 1 -> 'current_role_priv') > 0 - AND jsonb_array_length(col_info -> 1 -> 'valid_target_types') > 0, - 'current_role_priv and valid_target_types should be non-empty jsonb arrays' + jsonb_array_length(col_info -> 1 -> 'current_role_priv') > 0, + 'current_role_priv should be a non-empty jsonb array' ); -- Column 3 RETURN NEXT is( - (col_info -> 2) - ARRAY['current_role_priv', 'valid_target_types'], + (col_info -> 2) - ARRAY['current_role_priv'], $j${ "id": 3, "name": "var_128", "type": "character varying", "default": null, "nullable": true, "description": null, "primary_key": false, "type_options": {"length": 128}, @@ -2959,14 +2915,13 @@ BEGIN }$j$ ); RETURN NEXT ok( - jsonb_array_length(col_info -> 2 -> 'current_role_priv') > 0 - AND jsonb_array_length(col_info -> 2 -> 'valid_target_types') > 0, - 'current_role_priv and valid_target_types should be non-empty jsonb arrays' + jsonb_array_length(col_info -> 2 -> 'current_role_priv') > 0, + 'current_role_priv should be a non-empty jsonb array' ); -- Column 4 RETURN NEXT is( - (col_info -> 3) - ARRAY['current_role_priv', 'valid_target_types'], + (col_info -> 3) - ARRAY['current_role_priv'], $j${ "id": 4, "name": "txt", "type": "text", "default": {"value": "abc", "is_dynamic": false}, "nullable": true, "description": "A super comment ;", "primary_key": false, @@ -2974,14 +2929,13 @@ BEGIN }$j$ ); RETURN NEXT ok( - jsonb_array_length(col_info -> 3 -> 'current_role_priv') > 0 - AND jsonb_array_length(col_info -> 3 -> 'valid_target_types') > 0, - 'current_role_priv and valid_target_types should be non-empty jsonb arrays' + jsonb_array_length(col_info -> 3 -> 'current_role_priv') > 0, + 'current_role_priv should be a non-empty jsonb array' ); -- Column 5 RETURN NEXT is( - (col_info -> 4) - ARRAY['current_role_priv', 'valid_target_types'], + (col_info -> 4) - ARRAY['current_role_priv'], $j${ "id": 5, "name": "tst", "type": "timestamp without time zone", "default": {"value": "now()", "is_dynamic": true}, "nullable": true, "description": null, @@ -2989,14 +2943,13 @@ BEGIN }$j$ ); RETURN NEXT ok( - jsonb_array_length(col_info -> 4 -> 'current_role_priv') > 0 - AND jsonb_array_length(col_info -> 4 -> 'valid_target_types') > 0, - 'current_role_priv and valid_target_types should be non-empty jsonb arrays' + jsonb_array_length(col_info -> 4 -> 'current_role_priv') > 0, + 'current_role_priv should be a non-empty jsonb array' ); -- Column 6 RETURN NEXT is( - (col_info -> 5) - ARRAY['current_role_priv', 'valid_target_types'], + (col_info -> 5) - ARRAY['current_role_priv'], $j${ "id": 6, "name": "int_arr", "type": "_array", "default": null, "nullable": true, "description": null, "primary_key": false, "type_options": {"item_type": "integer"}, @@ -3004,14 +2957,13 @@ BEGIN }$j$ ); RETURN NEXT ok( - jsonb_array_length(col_info -> 5 -> 'current_role_priv') > 0 - AND col_info -> 5 -> 'valid_target_types' = 'null'::jsonb, - 'current_role_priv non-empty array, valid_target_types null' + jsonb_array_length(col_info -> 5 -> 'current_role_priv') > 0, + 'current_role_priv should be a non-empty jsonb array' ); -- Column 7 RETURN NEXT is( - (col_info -> 6) - ARRAY['current_role_priv', 'valid_target_types'], + (col_info -> 6) - ARRAY['current_role_priv'], $j${ "id": 7, "name": "num_opt_arr", "type": "_array", "default": null, "nullable": true, "description": null, "primary_key": false, @@ -3020,9 +2972,8 @@ BEGIN }$j$ ); RETURN NEXT ok( - jsonb_array_length(col_info -> 6 -> 'current_role_priv') > 0 - AND col_info -> 6 -> 'valid_target_types' = 'null'::jsonb, - 'current_role_priv non-empty array, valid_target_types null' + jsonb_array_length(col_info -> 6 -> 'current_role_priv') > 0, + 'current_role_priv should be a non-empty jsonb array' ); END; $$ LANGUAGE plpgsql; diff --git a/mathesar/rpc/columns/base.py b/mathesar/rpc/columns/base.py index 74be647f55..33e8c0a471 100644 --- a/mathesar/rpc/columns/base.py +++ b/mathesar/rpc/columns/base.py @@ -178,8 +178,6 @@ class ColumnInfo(TypedDict): has_dependents: Whether the column has dependent objects. description: The description of the column. current_role_priv: The privileges available to the user for the column. - valid_target_types: A list of all types to which the column can - be cast. """ id: int name: str @@ -191,7 +189,6 @@ class ColumnInfo(TypedDict): has_dependents: bool description: str current_role_priv: list[Literal['SELECT', 'INSERT', 'UPDATE', 'REFERENCES']] - valid_target_types: list[str] @classmethod def from_dict(cls, col_info): @@ -205,8 +202,7 @@ def from_dict(cls, col_info): default=ColumnDefault.from_dict(col_info.get("default")), has_dependents=col_info["has_dependents"], description=col_info.get("description"), - current_role_priv=col_info["current_role_priv"], - valid_target_types=col_info.get("valid_target_types") + current_role_priv=col_info["current_role_priv"] ) diff --git a/mathesar/tests/rpc/columns/test_c_base.py b/mathesar/tests/rpc/columns/test_c_base.py index 0641916160..befd35ea97 100644 --- a/mathesar/tests/rpc/columns/test_c_base.py +++ b/mathesar/tests/rpc/columns/test_c_base.py @@ -37,8 +37,7 @@ def mock_connect(_database_id, user): 'nullable': False, 'description': None, 'primary_key': True, 'type_options': None, 'has_dependents': True, - 'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'], - 'valid_target_types': ['text'] + 'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'] }, { 'id': 2, 'name': 'numcol', 'type': 'numeric', 'default': {'value': "'8'::numeric", 'is_dynamic': False}, @@ -47,32 +46,28 @@ def mock_connect(_database_id, user): 'primary_key': False, 'type_options': None, 'has_dependents': False, - 'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'], - 'valid_target_types': ['text'] + 'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'] }, { 'id': 4, 'name': 'numcolmod', 'type': 'numeric', 'default': None, 'nullable': True, 'description': None, 'primary_key': False, 'type_options': {'scale': 3, 'precision': 5}, 'has_dependents': False, - 'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'], - 'valid_target_types': ['text'] + 'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'] }, { 'id': 8, 'name': 'ivlcolmod', 'type': 'interval', 'default': None, 'nullable': True, 'description': None, 'primary_key': False, 'type_options': {'fields': 'day to second'}, 'has_dependents': False, - 'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'], - 'valid_target_types': ['text'] + 'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'] }, { 'id': 10, 'name': 'arrcol', 'type': '_array', 'default': None, 'nullable': True, 'description': None, 'primary_key': False, 'type_options': {'item_type': 'character varying', 'length': 3}, 'has_dependents': False, - 'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'], - 'valid_target_types': None + 'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'] } ] mocked_exec_msar_func.fetchone.return_value = [expect_col_list] diff --git a/mathesar_ui/src/api/rpc/columns.ts b/mathesar_ui/src/api/rpc/columns.ts index 3b5065595c..aeae12c221 100644 --- a/mathesar_ui/src/api/rpc/columns.ts +++ b/mathesar_ui/src/api/rpc/columns.ts @@ -168,7 +168,6 @@ interface RawColumn { primary_key: boolean; default: ColumnDefault | null; has_dependents: boolean; - valid_target_types: string[]; current_role_priv: ColumnPrivilege[]; } diff --git a/mathesar_ui/src/components/abstract-type-control/utils.ts b/mathesar_ui/src/components/abstract-type-control/utils.ts index 270970077b..5a0d57ea13 100644 --- a/mathesar_ui/src/components/abstract-type-control/utils.ts +++ b/mathesar_ui/src/components/abstract-type-control/utils.ts @@ -13,10 +13,7 @@ import type { FormBuildConfiguration } from '@mathesar-component-library/types'; import DurationConfiguration from './config-components/DurationConfiguration.svelte'; export interface ColumnWithAbstractType - extends Pick< - Column, - 'id' | 'type' | 'type_options' | 'metadata' | 'valid_target_types' - > { + extends Pick { abstractType: AbstractType; } diff --git a/mathesar_ui/src/stores/abstract-types/abstractTypeCategories.ts b/mathesar_ui/src/stores/abstract-types/abstractTypeCategories.ts index 77cfd7e7ac..0ad6da37bf 100644 --- a/mathesar_ui/src/stores/abstract-types/abstractTypeCategories.ts +++ b/mathesar_ui/src/stores/abstract-types/abstractTypeCategories.ts @@ -269,13 +269,6 @@ export function getAbstractTypeForDbType(dbType: DbType): AbstractType { return abstractTypeOfDbType; } -/** - * For columns, allowed db types should be an intersection of valid_target_types - * and dbTypes of each abstract type. i.e - * const allowedDBTypes = intersection(dbTargetTypeSet, abstractType.dbTypes); - * - * However, it is not handled here yet, since it requires additional confirmation. - */ export function getAllowedAbstractTypesForDbTypeAndItsTargetTypes( dbType: DbType, targetDbTypes: DbType[], diff --git a/mathesar_ui/src/stores/table-data/__tests__/utils.test.ts b/mathesar_ui/src/stores/table-data/__tests__/utils.test.ts index 382ab911af..e626f48a47 100644 --- a/mathesar_ui/src/stores/table-data/__tests__/utils.test.ts +++ b/mathesar_ui/src/stores/table-data/__tests__/utils.test.ts @@ -57,7 +57,6 @@ describe('getRowStatus', () => { primary_key: false, default: null, has_dependents: false, - valid_target_types: [], current_role_priv: [], metadata: null, },