Skip to content

Commit 15fe051

Browse files
authored
Merge pull request #4404 from mathesar-foundation/rm_valid_target_types
Remove valid_target_types
2 parents 88ab855 + b9f9d88 commit 15fe051

File tree

9 files changed

+32
-133
lines changed

9 files changed

+32
-133
lines changed

db/columns.py

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def get_column_info_for_table(table, conn):
3232
},
3333
"nullable": <bool>,
3434
"primary_key": <bool>,
35-
"valid_target_types": [<str>, <str>, ..., <str>]
3635
"default": {"value": <str>, "is_dynamic": <bool>},
3736
"has_dependents": <bool>,
3837
"current_role_priv": [<str>, <str>, ...],

db/sql/05_msar.sql

+2-32
Original file line numberDiff line numberDiff line change
@@ -857,34 +857,6 @@ SELECT nullif(
857857
$$ LANGUAGE SQL RETURNS NULL ON NULL INPUT;
858858

859859

860-
CREATE OR REPLACE FUNCTION msar.get_valid_target_type_strings(typ_id regtype) RETURNS jsonb AS $$/*
861-
Given a source type, return the target types for which Mathesar provides a casting function.
862-
863-
Args:
864-
typ_id: The type we're casting from.
865-
*/
866-
867-
SELECT jsonb_agg(prorettype::regtype::text)
868-
FROM pg_proc
869-
WHERE
870-
pronamespace=msar.get_schema_oid('msar')
871-
AND proargtypes[0]=
872-
CASE WHEN typ_id = ANY(ARRAY['smallint', 'integer', 'mathesar_types.mathesar_money']::regtype[])
873-
THEN 'numeric'::regtype
874-
WHEN typ_id = ANY(ARRAY['"char"', 'character', 'character varying', 'mathesar_types.email', 'mathesar_types.uri']::regtype[])
875-
THEN 'text'::regtype
876-
WHEN typ_id = ANY(ARRAY['mathesar_types.mathesar_json_array', 'mathesar_types.mathesar_json_object']::regtype[])
877-
THEN 'jsonb'::regtype
878-
WHEN typ_id = 'time without time zone'::regtype
879-
THEN 'time with time zone'::regtype
880-
WHEN typ_id = 'timestamp without time zone'::regtype
881-
THEN 'timestamp with time zone'::regtype
882-
ELSE typ_id
883-
END
884-
AND left(proname, 5) = 'cast_';
885-
$$ LANGUAGE SQL RETURNS NULL ON NULL INPUT;
886-
887-
888860
CREATE OR REPLACE FUNCTION msar.has_dependents(rel_id oid, att_id smallint) RETURNS boolean AS $$/*
889861
Return a boolean according to whether the column identified by the given oid, attnum pair is
890862
referenced (i.e., would dropping that column require CASCADE?).
@@ -989,8 +961,7 @@ Each returned JSON object in the array will have the form:
989961
"default": {"value": <str>, "is_dynamic": <bool>},
990962
"has_dependents": <bool>,
991963
"description": <str>,
992-
"current_role_priv": [<str>, <str>, ...],
993-
"valid_target_types": [<str>, <str>, ...]
964+
"current_role_priv": [<str>, <str>, ...]
994965
}
995966
996967
The `type_options` object is described in the docstring of `msar.get_type_options`. The `default`
@@ -1009,8 +980,7 @@ SELECT jsonb_agg(
1009980
'default', msar.describe_column_default(tab_id, attnum),
1010981
'has_dependents', msar.has_dependents(tab_id, attnum),
1011982
'description', msar.col_description(tab_id, attnum),
1012-
'current_role_priv', msar.list_column_privileges_for_current_role(tab_id, attnum),
1013-
'valid_target_types', msar.get_valid_target_type_strings(atttypid)
983+
'current_role_priv', msar.list_column_privileges_for_current_role(tab_id, attnum)
1014984
)
1015985
)
1016986
FROM pg_attribute pga

db/sql/test_sql_functions.sql

+23-72
Original file line numberDiff line numberDiff line change
@@ -2834,48 +2834,6 @@ END;
28342834
$$ LANGUAGE plpgsql;
28352835

28362836

2837-
CREATE OR REPLACE FUNCTION test_get_valid_target_type_strings() RETURNS SETOF TEXT AS $$
2838-
DECLARE
2839-
target_type_strings jsonb;
2840-
BEGIN
2841-
target_type_strings = msar.get_valid_target_type_strings('text');
2842-
RETURN NEXT is(jsonb_array_length(target_type_strings), 28);
2843-
RETURN NEXT ok(
2844-
target_type_strings @> jsonb_build_array(
2845-
'real', 'double precision', 'mathesar_types.email', 'smallint', 'boolean', 'bigint',
2846-
'integer', 'interval', 'time without time zone', 'time with time zone',
2847-
'timestamp with time zone', 'timestamp without time zone', 'date',
2848-
'mathesar_types.mathesar_money', 'money', 'mathesar_types.multicurrency_money',
2849-
'character varying', 'character', '"char"', 'text', 'name', 'mathesar_types.uri', 'numeric',
2850-
'jsonb', 'mathesar_types.mathesar_json_array', 'mathesar_types.mathesar_json_object', 'json', 'uuid'
2851-
),
2852-
'containment plus length checks order-independent equality'
2853-
);
2854-
target_type_strings = msar.get_valid_target_type_strings('text'::regtype::oid);
2855-
RETURN NEXT is(jsonb_array_length(target_type_strings), 28);
2856-
RETURN NEXT ok(
2857-
target_type_strings @> jsonb_build_array(
2858-
'real', 'double precision', 'mathesar_types.email', 'smallint', 'boolean', 'bigint',
2859-
'integer', 'interval', 'time without time zone', 'time with time zone',
2860-
'timestamp with time zone', 'timestamp without time zone', 'date',
2861-
'mathesar_types.mathesar_money', 'money', 'mathesar_types.multicurrency_money',
2862-
'character varying', 'character', '"char"', 'text', 'name', 'mathesar_types.uri', 'numeric',
2863-
'jsonb', 'mathesar_types.mathesar_json_array', 'mathesar_types.mathesar_json_object', 'json', 'uuid'
2864-
),
2865-
'containment plus length checks order-independent equality'
2866-
);
2867-
target_type_strings = msar.get_valid_target_type_strings('interval');
2868-
RETURN NEXT is(jsonb_array_length(target_type_strings), 6);
2869-
RETURN NEXT ok(
2870-
target_type_strings @> jsonb_build_array(
2871-
'interval', 'character varying', 'character', '"char"', 'text', 'name'
2872-
),
2873-
'containment plus length checks order-independent equality'
2874-
);
2875-
END;
2876-
$$ LANGUAGE plpgsql;
2877-
2878-
28792837
CREATE OR REPLACE FUNCTION test_has_dependents() RETURNS SETOF TEXT AS $$
28802838
BEGIN
28812839
PERFORM __setup_extract_fkey_cols();
@@ -2907,8 +2865,8 @@ $$ LANGUAGE plpgsql;
29072865

29082866

29092867
CREATE OR REPLACE FUNCTION test_get_column_info() RETURNS SETOF TEXT AS $$/*
2910-
This test doesn't inspect the contents of the current_role_priv or valid_target_types arrays, since
2911-
the functions that generate those contents are tested elsewhere. We just make sure the arrays exist,
2868+
This test doesn't inspect the contents of the current_role_priv array, since
2869+
the functions that generate those contents are tested elsewhere. We just make sure the array exist,
29122870
and are non-empty. All other contents of the returned jsonb are tested.
29132871
*/
29142872
DECLARE
@@ -2920,7 +2878,7 @@ BEGIN
29202878

29212879
-- Column 1
29222880
RETURN NEXT is(
2923-
(col_info -> 0) - ARRAY['current_role_priv', 'valid_target_types'],
2881+
(col_info -> 0) - ARRAY['current_role_priv'],
29242882
$j${
29252883
"id": 1, "name": "id", "type": "integer",
29262884
"default": {"value": "identity", "is_dynamic": true},
@@ -2929,89 +2887,83 @@ BEGIN
29292887
}$j$
29302888
);
29312889
RETURN NEXT ok(
2932-
jsonb_array_length(col_info -> 0 -> 'current_role_priv') > 0
2933-
AND jsonb_array_length(col_info -> 0 -> 'valid_target_types') > 0,
2934-
'current_role_priv and valid_target_types should be non-empty jsonb arrays'
2890+
jsonb_array_length(col_info -> 0 -> 'current_role_priv') > 0,
2891+
'current_role_priv should be a non-empty jsonb array'
29352892
);
29362893

29372894
-- Column 2
29382895
RETURN NEXT is(
2939-
(col_info -> 1) - ARRAY['current_role_priv', 'valid_target_types'],
2896+
(col_info -> 1) - ARRAY['current_role_priv'],
29402897
$j${
29412898
"id": 2, "name": "num_plain", "type": "numeric", "default": null, "nullable": false,
29422899
"description": null, "primary_key": false, "type_options": {"scale": null, "precision": null},
29432900
"has_dependents": false
29442901
}$j$
29452902
);
29462903
RETURN NEXT ok(
2947-
jsonb_array_length(col_info -> 1 -> 'current_role_priv') > 0
2948-
AND jsonb_array_length(col_info -> 1 -> 'valid_target_types') > 0,
2949-
'current_role_priv and valid_target_types should be non-empty jsonb arrays'
2904+
jsonb_array_length(col_info -> 1 -> 'current_role_priv') > 0,
2905+
'current_role_priv should be a non-empty jsonb array'
29502906
);
29512907

29522908
-- Column 3
29532909
RETURN NEXT is(
2954-
(col_info -> 2) - ARRAY['current_role_priv', 'valid_target_types'],
2910+
(col_info -> 2) - ARRAY['current_role_priv'],
29552911
$j${
29562912
"id": 3, "name": "var_128", "type": "character varying", "default": null, "nullable": true,
29572913
"description": null, "primary_key": false, "type_options": {"length": 128},
29582914
"has_dependents": false
29592915
}$j$
29602916
);
29612917
RETURN NEXT ok(
2962-
jsonb_array_length(col_info -> 2 -> 'current_role_priv') > 0
2963-
AND jsonb_array_length(col_info -> 2 -> 'valid_target_types') > 0,
2964-
'current_role_priv and valid_target_types should be non-empty jsonb arrays'
2918+
jsonb_array_length(col_info -> 2 -> 'current_role_priv') > 0,
2919+
'current_role_priv should be a non-empty jsonb array'
29652920
);
29662921

29672922
-- Column 4
29682923
RETURN NEXT is(
2969-
(col_info -> 3) - ARRAY['current_role_priv', 'valid_target_types'],
2924+
(col_info -> 3) - ARRAY['current_role_priv'],
29702925
$j${
29712926
"id": 4, "name": "txt", "type": "text", "default": {"value": "abc", "is_dynamic": false},
29722927
"nullable": true, "description": "A super comment ;", "primary_key": false,
29732928
"type_options": null, "has_dependents": false
29742929
}$j$
29752930
);
29762931
RETURN NEXT ok(
2977-
jsonb_array_length(col_info -> 3 -> 'current_role_priv') > 0
2978-
AND jsonb_array_length(col_info -> 3 -> 'valid_target_types') > 0,
2979-
'current_role_priv and valid_target_types should be non-empty jsonb arrays'
2932+
jsonb_array_length(col_info -> 3 -> 'current_role_priv') > 0,
2933+
'current_role_priv should be a non-empty jsonb array'
29802934
);
29812935

29822936
-- Column 5
29832937
RETURN NEXT is(
2984-
(col_info -> 4) - ARRAY['current_role_priv', 'valid_target_types'],
2938+
(col_info -> 4) - ARRAY['current_role_priv'],
29852939
$j${
29862940
"id": 5, "name": "tst", "type": "timestamp without time zone",
29872941
"default": {"value": "now()", "is_dynamic": true}, "nullable": true, "description": null,
29882942
"primary_key": false, "type_options": {"precision": null}, "has_dependents": false
29892943
}$j$
29902944
);
29912945
RETURN NEXT ok(
2992-
jsonb_array_length(col_info -> 4 -> 'current_role_priv') > 0
2993-
AND jsonb_array_length(col_info -> 4 -> 'valid_target_types') > 0,
2994-
'current_role_priv and valid_target_types should be non-empty jsonb arrays'
2946+
jsonb_array_length(col_info -> 4 -> 'current_role_priv') > 0,
2947+
'current_role_priv should be a non-empty jsonb array'
29952948
);
29962949

29972950
-- Column 6
29982951
RETURN NEXT is(
2999-
(col_info -> 5) - ARRAY['current_role_priv', 'valid_target_types'],
2952+
(col_info -> 5) - ARRAY['current_role_priv'],
30002953
$j${
30012954
"id": 6, "name": "int_arr", "type": "_array", "default": null, "nullable": true,
30022955
"description": null, "primary_key": false, "type_options": {"item_type": "integer"},
30032956
"has_dependents": false
30042957
}$j$
30052958
);
30062959
RETURN NEXT ok(
3007-
jsonb_array_length(col_info -> 5 -> 'current_role_priv') > 0
3008-
AND col_info -> 5 -> 'valid_target_types' = 'null'::jsonb,
3009-
'current_role_priv non-empty array, valid_target_types null'
2960+
jsonb_array_length(col_info -> 5 -> 'current_role_priv') > 0,
2961+
'current_role_priv should be a non-empty jsonb array'
30102962
);
30112963

30122964
-- Column 7
30132965
RETURN NEXT is(
3014-
(col_info -> 6) - ARRAY['current_role_priv', 'valid_target_types'],
2966+
(col_info -> 6) - ARRAY['current_role_priv'],
30152967
$j${
30162968
"id": 7, "name": "num_opt_arr", "type": "_array", "default": null, "nullable": true,
30172969
"description": null, "primary_key": false,
@@ -3020,9 +2972,8 @@ BEGIN
30202972
}$j$
30212973
);
30222974
RETURN NEXT ok(
3023-
jsonb_array_length(col_info -> 6 -> 'current_role_priv') > 0
3024-
AND col_info -> 6 -> 'valid_target_types' = 'null'::jsonb,
3025-
'current_role_priv non-empty array, valid_target_types null'
2975+
jsonb_array_length(col_info -> 6 -> 'current_role_priv') > 0,
2976+
'current_role_priv should be a non-empty jsonb array'
30262977
);
30272978
END;
30282979
$$ LANGUAGE plpgsql;

mathesar/rpc/columns/base.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ class ColumnInfo(TypedDict):
178178
has_dependents: Whether the column has dependent objects.
179179
description: The description of the column.
180180
current_role_priv: The privileges available to the user for the column.
181-
valid_target_types: A list of all types to which the column can
182-
be cast.
183181
"""
184182
id: int
185183
name: str
@@ -191,7 +189,6 @@ class ColumnInfo(TypedDict):
191189
has_dependents: bool
192190
description: str
193191
current_role_priv: list[Literal['SELECT', 'INSERT', 'UPDATE', 'REFERENCES']]
194-
valid_target_types: list[str]
195192

196193
@classmethod
197194
def from_dict(cls, col_info):
@@ -205,8 +202,7 @@ def from_dict(cls, col_info):
205202
default=ColumnDefault.from_dict(col_info.get("default")),
206203
has_dependents=col_info["has_dependents"],
207204
description=col_info.get("description"),
208-
current_role_priv=col_info["current_role_priv"],
209-
valid_target_types=col_info.get("valid_target_types")
205+
current_role_priv=col_info["current_role_priv"]
210206
)
211207

212208

mathesar/tests/rpc/columns/test_c_base.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ def mock_connect(_database_id, user):
3737
'nullable': False, 'description': None, 'primary_key': True,
3838
'type_options': None,
3939
'has_dependents': True,
40-
'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'],
41-
'valid_target_types': ['text']
40+
'current_role_priv': ['SELECT', 'INSERT', 'UPDATE']
4241
}, {
4342
'id': 2, 'name': 'numcol', 'type': 'numeric',
4443
'default': {'value': "'8'::numeric", 'is_dynamic': False},
@@ -47,32 +46,28 @@ def mock_connect(_database_id, user):
4746
'primary_key': False,
4847
'type_options': None,
4948
'has_dependents': False,
50-
'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'],
51-
'valid_target_types': ['text']
49+
'current_role_priv': ['SELECT', 'INSERT', 'UPDATE']
5250
}, {
5351
'id': 4, 'name': 'numcolmod', 'type': 'numeric',
5452
'default': None,
5553
'nullable': True, 'description': None, 'primary_key': False,
5654
'type_options': {'scale': 3, 'precision': 5},
5755
'has_dependents': False,
58-
'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'],
59-
'valid_target_types': ['text']
56+
'current_role_priv': ['SELECT', 'INSERT', 'UPDATE']
6057
}, {
6158
'id': 8, 'name': 'ivlcolmod', 'type': 'interval',
6259
'default': None,
6360
'nullable': True, 'description': None, 'primary_key': False,
6461
'type_options': {'fields': 'day to second'},
6562
'has_dependents': False,
66-
'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'],
67-
'valid_target_types': ['text']
63+
'current_role_priv': ['SELECT', 'INSERT', 'UPDATE']
6864
}, {
6965
'id': 10, 'name': 'arrcol', 'type': '_array',
7066
'default': None,
7167
'nullable': True, 'description': None, 'primary_key': False,
7268
'type_options': {'item_type': 'character varying', 'length': 3},
7369
'has_dependents': False,
74-
'current_role_priv': ['SELECT', 'INSERT', 'UPDATE'],
75-
'valid_target_types': None
70+
'current_role_priv': ['SELECT', 'INSERT', 'UPDATE']
7671
}
7772
]
7873
mocked_exec_msar_func.fetchone.return_value = [expect_col_list]

mathesar_ui/src/api/rpc/columns.ts

-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ interface RawColumn {
168168
primary_key: boolean;
169169
default: ColumnDefault | null;
170170
has_dependents: boolean;
171-
valid_target_types: string[];
172171
current_role_priv: ColumnPrivilege[];
173172
}
174173

mathesar_ui/src/components/abstract-type-control/utils.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ import type { FormBuildConfiguration } from '@mathesar-component-library/types';
1313
import DurationConfiguration from './config-components/DurationConfiguration.svelte';
1414

1515
export interface ColumnWithAbstractType
16-
extends Pick<
17-
Column,
18-
'id' | 'type' | 'type_options' | 'metadata' | 'valid_target_types'
19-
> {
16+
extends Pick<Column, 'id' | 'type' | 'type_options' | 'metadata'> {
2017
abstractType: AbstractType;
2118
}
2219

mathesar_ui/src/stores/abstract-types/abstractTypeCategories.ts

-7
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,6 @@ export function getAbstractTypeForDbType(dbType: DbType): AbstractType {
269269
return abstractTypeOfDbType;
270270
}
271271

272-
/**
273-
* For columns, allowed db types should be an intersection of valid_target_types
274-
* and dbTypes of each abstract type. i.e
275-
* const allowedDBTypes = intersection(dbTargetTypeSet, abstractType.dbTypes);
276-
*
277-
* However, it is not handled here yet, since it requires additional confirmation.
278-
*/
279272
export function getAllowedAbstractTypesForDbTypeAndItsTargetTypes(
280273
dbType: DbType,
281274
targetDbTypes: DbType[],

mathesar_ui/src/stores/table-data/__tests__/utils.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ describe('getRowStatus', () => {
5757
primary_key: false,
5858
default: null,
5959
has_dependents: false,
60-
valid_target_types: [],
6160
current_role_priv: [],
6261
metadata: null,
6362
},

0 commit comments

Comments
 (0)