Skip to content

Remove valid_target_types #4404

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

Merged
merged 7 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion db/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def get_column_info_for_table(table, conn):
},
"nullable": <bool>,
"primary_key": <bool>,
"valid_target_types": [<str>, <str>, ..., <str>]
"default": {"value": <str>, "is_dynamic": <bool>},
"has_dependents": <bool>,
"current_role_priv": [<str>, <str>, ...],
Expand Down
34 changes: 2 additions & 32 deletions db/sql/05_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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?).
Expand Down Expand Up @@ -989,8 +961,7 @@ Each returned JSON object in the array will have the form:
"default": {"value": <str>, "is_dynamic": <bool>},
"has_dependents": <bool>,
"description": <str>,
"current_role_priv": [<str>, <str>, ...],
"valid_target_types": [<str>, <str>, ...]
"current_role_priv": [<str>, <str>, ...]
}

The `type_options` object is described in the docstring of `msar.get_type_options`. The `default`
Expand All @@ -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
Expand Down
95 changes: 23 additions & 72 deletions db/sql/test_sql_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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},
Expand All @@ -2929,89 +2887,83 @@ 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},
"has_dependents": false
}$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},
"has_dependents": false
}$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,
"type_options": null, "has_dependents": false
}$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,
"primary_key": false, "type_options": {"precision": null}, "has_dependents": false
}$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"},
"has_dependents": false
}$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,
Expand All @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions mathesar/rpc/columns/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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"]
)


Expand Down
15 changes: 5 additions & 10 deletions mathesar/tests/rpc/columns/test_c_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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]
Expand Down
1 change: 0 additions & 1 deletion mathesar_ui/src/api/rpc/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ interface RawColumn {
primary_key: boolean;
default: ColumnDefault | null;
has_dependents: boolean;
valid_target_types: string[];
current_role_priv: ColumnPrivilege[];
}

Expand Down
5 changes: 1 addition & 4 deletions mathesar_ui/src/components/abstract-type-control/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Column, 'id' | 'type' | 'type_options' | 'metadata'> {
abstractType: AbstractType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[],
Expand Down
1 change: 0 additions & 1 deletion mathesar_ui/src/stores/table-data/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { get, readable } from 'svelte/store';

Check warning on line 1 in mathesar_ui/src/stores/table-data/__tests__/utils.test.ts

View workflow job for this annotation

GitHub Actions / Run front end linter

'get' is defined but never used
import { _ } from 'svelte-i18n';

Check warning on line 2 in mathesar_ui/src/stores/table-data/__tests__/utils.test.ts

View workflow job for this annotation

GitHub Actions / Run front end linter

'_' is defined but never used

import type { RequestStatus } from '@mathesar/api/rest/utils/requestUtils';
import { ImmutableMap } from '@mathesar/component-library';
Expand Down Expand Up @@ -57,7 +57,6 @@
primary_key: false,
default: null,
has_dependents: false,
valid_target_types: [],
current_role_priv: [],
metadata: null,
},
Expand Down
Loading