mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-07 22:53:45 -06:00
Fixed issues in create collation. #5611
This commit is contained in:
parent
082fb165d3
commit
053b1e3d69
Binary file not shown.
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 11 KiB |
@ -22,6 +22,8 @@ export default class CollationSchema extends BaseUISchema {
|
||||
lc_type: undefined,
|
||||
lc_collate: undefined,
|
||||
description: undefined,
|
||||
provider: 'libc',
|
||||
is_deterministic: true,
|
||||
schema: null,
|
||||
...initValues
|
||||
});
|
||||
@ -83,11 +85,45 @@ export default class CollationSchema extends BaseUISchema {
|
||||
},
|
||||
deps: ['locale', 'lc_collate', 'lc_type'],
|
||||
},
|
||||
{
|
||||
id: 'provider', label: gettext('Locale Provider'),
|
||||
editable: false, type: 'select',mode: ['create', 'edit'], group: gettext('Definition'),
|
||||
readonly: function (state) { return !obj.isNew(state); },
|
||||
options: [{
|
||||
label: gettext('icu'),
|
||||
value: 'icu',
|
||||
}, {
|
||||
label: gettext('libc'),
|
||||
value: 'libc',
|
||||
}],
|
||||
min_version: 110000,
|
||||
deps: ['copy_collation'],
|
||||
depChange: (state)=>{
|
||||
if (state.copy_collation)
|
||||
return { provider: '' };
|
||||
if (state.provider)
|
||||
return { provider: state.provider };
|
||||
return { provider: 'libc' };
|
||||
},
|
||||
disabled: function (state) {
|
||||
return state.copy_collation;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'provider', label: gettext('Locale Provider'),
|
||||
type: 'text',mode: ['properties'], group: gettext('Definition'),
|
||||
readonly: true,
|
||||
min_version: 110000,
|
||||
},
|
||||
{
|
||||
id: 'locale', label: gettext('Locale'),
|
||||
type: 'text', mode: ['create', 'edit'], group: gettext('Definition'),
|
||||
readonly: function (state) { return !obj.isNew(state); },
|
||||
deps: ['lc_collate', 'lc_type', 'copy_collation'],
|
||||
deps: ['lc_collate', 'lc_type', 'copy_collation','provider'],
|
||||
depChange: (state)=>{
|
||||
if (state.lc_collate || state.lc_type)
|
||||
return { locale: '' };
|
||||
},
|
||||
disabled: function (state) {
|
||||
// Enable locale only if lc_* & copy_collation is not provided
|
||||
if (state.lc_collate || state.lc_type)
|
||||
@ -99,43 +135,21 @@ export default class CollationSchema extends BaseUISchema {
|
||||
id: 'lc_collate', label: gettext('LC_COLLATE'),
|
||||
type: 'text', mode: ['properties', 'create', 'edit'], group: gettext('Definition'),
|
||||
readonly: function (state) { return !obj.isNew(state); },
|
||||
depChange: obj.depChangeFields,
|
||||
disabled: obj.disableFields,
|
||||
deps: ['locale', 'copy_collation'],
|
||||
deps: ['locale', 'copy_collation','provider'],
|
||||
},
|
||||
{
|
||||
id: 'lc_type', label: gettext('LC_TYPE'),
|
||||
type: 'text', mode: ['properties', 'create', 'edit'], group: gettext('Definition'),
|
||||
readonly: function (state) { return !obj.isNew(state); },
|
||||
depChange: obj.depChangeFields,
|
||||
disabled: obj.disableFields,
|
||||
deps: ['locale', 'copy_collation'],
|
||||
},
|
||||
{
|
||||
id: 'provider', label: gettext('Locale Provider'),
|
||||
editable: false, type: 'select',mode: ['create', 'edit'], group: gettext('Definition'),
|
||||
readonly: function (state) { return !obj.isNew(state); },
|
||||
options: [{
|
||||
label: gettext('icu'),
|
||||
value: 'icu',
|
||||
}, {
|
||||
label: gettext('libc'),
|
||||
value: 'libc',
|
||||
}],
|
||||
min_version: 120000,
|
||||
deps: ['copy_collation'],
|
||||
disabled: function (state) {
|
||||
return state.copy_collation;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'provider', label: gettext('Locale Provider'),
|
||||
type: 'text',mode: ['properties'], group: gettext('Definition'),
|
||||
readonly: true,
|
||||
min_version: 120000,
|
||||
deps: ['locale', 'copy_collation', 'provider'],
|
||||
},
|
||||
{
|
||||
id: 'is_deterministic', label: gettext('Deterministic'),
|
||||
type: 'switch', group: gettext('Definition'),
|
||||
default: false,
|
||||
readonly: function (state) { return !obj.isNew(state); },
|
||||
mode: ['properties', 'edit', 'create'],
|
||||
min_version: 120000,
|
||||
@ -143,34 +157,52 @@ export default class CollationSchema extends BaseUISchema {
|
||||
deps: ['copy_collation'],
|
||||
disabled: function (state) {
|
||||
return state.copy_collation;
|
||||
}
|
||||
},
|
||||
depChange: (state, source, topState, actionObj)=>{
|
||||
if (state.copy_collation) {
|
||||
return { is_deterministic: false };
|
||||
}
|
||||
else {
|
||||
if (actionObj.oldState.is_deterministic) {
|
||||
return { is_deterministic: false };
|
||||
} else {
|
||||
return { is_deterministic: true };
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'version', label: gettext('Version'), type: 'text', group: gettext('Definition'),
|
||||
readonly: function (state) { return !obj.isNew(state); },
|
||||
mode: ['properties','create', 'edit'], min_version: 110000,
|
||||
deps: ['copy_collation'],
|
||||
disabled: function (state) {
|
||||
return state.copy_collation;
|
||||
},
|
||||
depChange: (state)=>{
|
||||
if (state.copy_collation)
|
||||
return { version: '' };
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'rules', label: gettext('Rules'),
|
||||
editable: true, type: 'text', group: gettext('Definition'),
|
||||
editable: false, type: 'text', group: gettext('Definition'),
|
||||
readonly: function (state) { return !obj.isNew(state); },
|
||||
mode: ['properties', 'edit', 'create'],
|
||||
deps: ['provider','is_deterministic','copy_collation'],
|
||||
deps: ['provider', 'copy_collation'],
|
||||
depChange: (state)=>{
|
||||
if (state.copy_collation)
|
||||
return { rules: '' };
|
||||
if (state.provider !== 'icu')
|
||||
return { rules: '' };
|
||||
},
|
||||
disabled: function(state) {
|
||||
if (state.copy_collation)
|
||||
return true;
|
||||
return state.provider !== 'icu' || (state.provider == 'icu' && state.is_deterministic);
|
||||
return state.provider !== 'icu';
|
||||
},
|
||||
min_version: 160000,
|
||||
},
|
||||
{
|
||||
id: 'version', label: gettext('Version'), type: 'text', group: gettext('Definition'),
|
||||
readonly: function (state) { return !obj.isNew(state); },
|
||||
mode: ['properties','create', 'edit'], min_version: 120000,
|
||||
deps: ['copy_collation'],
|
||||
disabled: function (state) {
|
||||
return state.copy_collation;
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 'is_sys_obj', label: gettext('System collation?'),
|
||||
cell: 'boolean', type: 'switch', mode: ['properties'],
|
||||
@ -181,9 +213,14 @@ export default class CollationSchema extends BaseUISchema {
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
depChangeFields(state){
|
||||
if (state.provider === 'icu')
|
||||
return { lc_type: '' , lc_collate: '' };
|
||||
}
|
||||
disableFields(state) {
|
||||
// Enable lc_* only if copy_collation & locale is not provided
|
||||
if (state.provider === 'icu')
|
||||
return true;
|
||||
if (state.locale || state.copy_collation) {
|
||||
if (state.locale)
|
||||
return true;
|
||||
@ -217,6 +254,16 @@ export default class CollationSchema extends BaseUISchema {
|
||||
if (isEmptyString(state.lc_type)) {
|
||||
lc_type_flag = true;
|
||||
}
|
||||
if (!lc_coll_flag && lc_type_flag){
|
||||
errmsg = gettext('Definition incomplete. Please provide LC_TYPE.');
|
||||
setError('lc_type', errmsg);
|
||||
return true;
|
||||
}
|
||||
if (!lc_type_flag && lc_coll_flag){
|
||||
errmsg = gettext('Definition incomplete. Please provide LC_COLLATE.');
|
||||
setError('lc_collate', errmsg);
|
||||
return true;
|
||||
}
|
||||
if (locale_flag && (lc_coll_flag || lc_type_flag) && copy_coll_flag) {
|
||||
errmsg = gettext('Definition incomplete. Please provide Locale OR Copy Collation OR LC_TYPE/LC_COLLATE.');
|
||||
setError('copy_collation', errmsg);
|
||||
|
@ -0,0 +1,59 @@
|
||||
{% if data %}
|
||||
CREATE COLLATION{% if add_not_exists_clause %} IF NOT EXISTS{% endif %} {{ conn|qtIdent(data.schema, data.name) }}
|
||||
{% if not data.copy_collation %}
|
||||
{% set options = [] %}
|
||||
{# if user has provided lc_collate & lc_type #}
|
||||
{% if data.lc_collate and data.lc_type %}
|
||||
{% if data.lc_collate and data.lc_type %}
|
||||
{% set options = options + ['LC_COLLATE = ' ~ data.lc_collate|qtLiteral(conn), 'LC_CTYPE = ' ~ data.lc_type|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.provider %}
|
||||
{% set options = options + ['PROVIDER = ' ~ data.provider|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.is_deterministic is defined %}
|
||||
{% set options = options + ['DETERMINISTIC = ' ~ data.is_deterministic|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.rules %}
|
||||
{% set options = options + ['RULES = ' ~ data.rules|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.version %}
|
||||
{% set options = options + ['VERSION = ' ~ data.version|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{# if user has provided locale only #}
|
||||
{% if data.locale %}
|
||||
{% if data.locale %}
|
||||
{% set options = options + ['LOCALE = ' ~ data.locale|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.provider %}
|
||||
{% set options = options + ['PROVIDER = ' ~ data.provider|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.is_deterministic is defined %}
|
||||
{% set options = options + ['DETERMINISTIC = ' ~ data.is_deterministic|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.rules %}
|
||||
{% set options = options + ['RULES = ' ~ data.rules|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.version %}
|
||||
{% set options = options + ['VERSION = ' ~ data.version|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if options %}
|
||||
({{ options|join(', ') }});
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{# if user has choosed to copy from existing collation #}
|
||||
{% if data.copy_collation %}
|
||||
FROM {{ data.copy_collation }};
|
||||
{% endif %}
|
||||
{% if data.owner %}
|
||||
|
||||
ALTER COLLATION {{ conn|qtIdent(data.schema, data.name) }}
|
||||
OWNER TO {{ conn|qtIdent(data.owner) }};
|
||||
{% endif %}
|
||||
{% if data.description %}
|
||||
|
||||
COMMENT ON COLLATION {{ conn|qtIdent(data.schema, data.name) }}
|
||||
IS {{ data.description|qtLiteral(conn) }};
|
||||
{% endif %}
|
||||
{% endif %}
|
@ -0,0 +1,10 @@
|
||||
SELECT c.oid, c.collname AS name, c.collcollate AS lc_collate, c.collctype AS lc_type,
|
||||
pg_catalog.pg_get_userbyid(c.collowner) AS owner, c.collisdeterministic AS is_deterministic, c.collversion AS version,
|
||||
c.collprovider AS provider, des.description, n.nspname AS schema
|
||||
|
||||
FROM pg_catalog.pg_collation c
|
||||
JOIN pg_catalog.pg_namespace n ON n.oid=c.collnamespace
|
||||
LEFT OUTER JOIN pg_catalog.pg_description des ON (des.objoid=c.oid AND des.classoid='pg_collation'::regclass)
|
||||
WHERE c.collnamespace = {{scid}}::oid
|
||||
{% if coid %} AND c.oid = {{coid}}::oid {% endif %}
|
||||
ORDER BY c.collname;
|
@ -1,6 +1,6 @@
|
||||
SELECT c.oid, c.collname AS name, COALESCE(c.collcollate, c.colliculocale) AS lc_collate,
|
||||
COALESCE(c.collctype, c.colliculocale) AS lc_type, c.collisdeterministic AS is_deterministic, c.collversion AS version,
|
||||
c.collprovider AS provider, c.collprovider AS rules,
|
||||
c.collprovider AS provider, c.collicurules AS rules,
|
||||
pg_catalog.pg_get_userbyid(c.collowner) AS owner, description, n.nspname AS schema
|
||||
FROM pg_catalog.pg_collation c
|
||||
JOIN pg_catalog.pg_namespace n ON n.oid=c.collnamespace
|
||||
|
@ -1,35 +1,33 @@
|
||||
{% if data %}
|
||||
CREATE COLLATION{% if add_not_exists_clause %} IF NOT EXISTS{% endif %} {{ conn|qtIdent(data.schema, data.name) }}
|
||||
{% if not data.copy_collation %}
|
||||
{% set options = [] %}
|
||||
{# if user has provided lc_collate & lc_type #}
|
||||
{% if data.lc_collate and data.lc_type and data.provider and data.is_deterministic%}
|
||||
{% if data.version %}
|
||||
(LC_COLLATE = {{ data.lc_collate|qtLiteral(conn) }}, LC_CTYPE = {{ data.lc_type|qtLiteral(conn) }}, PROVIDER = {{ data.provider|qtLiteral(conn) }}, DETERMINISTIC = {{ data.is_deterministic|qtLiteral(conn) }}, VERSION = {{ data.version|qtLiteral(conn) }});
|
||||
{% else %}
|
||||
(LC_COLLATE = {{ data.lc_collate|qtLiteral(conn) }}, LC_CTYPE = {{ data.lc_type|qtLiteral(conn) }}, PROVIDER = {{ data.provider|qtLiteral(conn) }}, DETERMINISTIC = {{ data.is_deterministic|qtLiteral(conn) }});
|
||||
{% if data.lc_collate and data.lc_type %}
|
||||
{% if data.lc_collate and data.lc_type %}
|
||||
{% set options = options + ['LC_COLLATE = ' ~ data.lc_collate|qtLiteral(conn), 'LC_CTYPE = ' ~ data.lc_type|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.provider %}
|
||||
{% set options = options + ['PROVIDER = ' ~ data.provider|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.lc_collate and data.lc_type and data.provider and not data.is_deterministic and data.rules %}
|
||||
{% if data.version %}
|
||||
(LC_COLLATE = {{ data.lc_collate|qtLiteral(conn) }}, LC_CTYPE = {{ data.lc_type|qtLiteral(conn) }}, PROVIDER = {{ data.provider|qtLiteral(conn) }}, RULES = {{ data.rules|qtLiteral(conn) }}, VERSION = {{ data.version|qtLiteral(conn) }}, DETERMINISTIC = FALSE);
|
||||
{% else %}
|
||||
(LC_COLLATE = {{ data.lc_collate|qtLiteral(conn) }}, LC_CTYPE = {{ data.lc_type|qtLiteral(conn) }}, PROVIDER = {{ data.provider|qtLiteral(conn) }}, RULES = {{ data.rules|qtLiteral(conn) }}, DETERMINISTIC = FALSE);
|
||||
{% set options = options + ['VERSION = ' ~ data.version|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{# if user has provided locale only #}
|
||||
{% if data.locale and data.provider and data.is_deterministic%}
|
||||
{% if data.locale %}
|
||||
{% if data.locale %}
|
||||
{% set options = options + ['LOCALE = ' ~ data.locale|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.provider %}
|
||||
{% set options = options + ['PROVIDER = ' ~ data.provider|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% if data.version %}
|
||||
(LOCALE = {{ data.locale|qtLiteral(conn) }}, PROVIDER = {{ data.provider|qtLiteral(conn) }}, DETERMINISTIC = {{ data.is_deterministic|qtLiteral(conn) }}, VERSION = {{ data.version|qtLiteral(conn) }});
|
||||
{% else %}
|
||||
(LOCALE = {{ data.locale|qtLiteral(conn) }}, PROVIDER = {{ data.provider|qtLiteral(conn) }}, DETERMINISTIC = {{ data.is_deterministic|qtLiteral(conn) }});
|
||||
{% set options = options + ['VERSION = ' ~ data.version|qtLiteral(conn)] %}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if data.locale and data.provider and data.version and not data.is_deterministic and data.rules %}
|
||||
{% if data.version %}
|
||||
(LOCALE = {{ data.locale|qtLiteral(conn) }}, PROVIDER = {{ data.provider|qtLiteral(conn) }}, RULES = {{ data.rules|qtLiteral(conn) }}, VERSION = {{ data.version|qtLiteral(conn) }}, DETERMINISTIC = FALSE);
|
||||
{% else %}
|
||||
(LOCALE = {{ data.locale|qtLiteral(conn) }}, PROVIDER = {{ data.provider|qtLiteral(conn) }}, RULES = {{ data.rules|qtLiteral(conn) }}, DETERMINISTIC = FALSE);
|
||||
{% endif %}
|
||||
{% if options %}
|
||||
({{ options|join(', ') }});
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{# if user has choosed to copy from existing collation #}
|
||||
|
@ -1,6 +1,6 @@
|
||||
SELECT c.oid, c.collname AS name, c.collcollate AS lc_collate, c.collctype AS lc_type,
|
||||
pg_catalog.pg_get_userbyid(c.collowner) AS owner, c.collisdeterministic AS is_deterministic, c.collversion AS version,
|
||||
c.collprovider AS provider, c.description, n.nspname AS schema
|
||||
pg_catalog.pg_get_userbyid(c.collowner) AS owner, c.collversion AS version,
|
||||
c.collprovider AS provider, des.description, n.nspname AS schema
|
||||
|
||||
FROM pg_catalog.pg_collation c
|
||||
JOIN pg_catalog.pg_namespace n ON n.oid=c.collnamespace
|
||||
|
@ -102,10 +102,6 @@
|
||||
"name": "Get Collation",
|
||||
"url": "/browser/collation/obj/",
|
||||
"is_positive_test": true,
|
||||
"inventory_data": {
|
||||
"server_min_version": 160000,
|
||||
"skip_msg": "Get Collation are not supported by PG 16.0 and below."
|
||||
},
|
||||
"mocking_required": false,
|
||||
"mock_data": {},
|
||||
"expected_data": {
|
||||
@ -117,10 +113,6 @@
|
||||
"url": "/browser/collation/obj/",
|
||||
"error_fetching_collation": true,
|
||||
"is_positive_test": false,
|
||||
"inventory_data": {
|
||||
"server_min_version": 160000,
|
||||
"skip_msg": "Error while fetching a Collation are not supported by PG 16.0 and below."
|
||||
},
|
||||
"mocking_required": true,
|
||||
"mock_data": {
|
||||
"function_name": "pgadmin.utils.driver.psycopg3.connection.Connection.execute_dict",
|
||||
@ -135,10 +127,6 @@
|
||||
"url": "/browser/collation/obj/",
|
||||
"wrong_collation_id": true,
|
||||
"is_positive_test": false,
|
||||
"inventory_data": {
|
||||
"server_min_version": 160000,
|
||||
"skip_msg": "Fetch collation using wrong collation id are not supported by PG 16.0 and below."
|
||||
},
|
||||
"mocking_required": false,
|
||||
"mock_data": {
|
||||
},
|
||||
@ -150,10 +138,6 @@
|
||||
"name": "Get Collation list",
|
||||
"url": "/browser/collation/obj/",
|
||||
"is_positive_test": true,
|
||||
"inventory_data": {
|
||||
"server_min_version": 160000,
|
||||
"skip_msg": "Get Collation list are not supported by PG 16.0 and below."
|
||||
},
|
||||
"collation_list": true,
|
||||
"mocking_required": false,
|
||||
"mock_data": {},
|
||||
@ -234,10 +218,6 @@
|
||||
"name": "Update Collation",
|
||||
"url": "/browser/collation/obj/",
|
||||
"is_positive_test": true,
|
||||
"inventory_data": {
|
||||
"server_min_version": 160000,
|
||||
"skip_msg": "Update Collation are not supported by PG 16.0 and below."
|
||||
},
|
||||
"mocking_required": false,
|
||||
"test_data": {
|
||||
"description": "This is collation update comment",
|
||||
@ -401,10 +381,6 @@
|
||||
"name": "Get Collation SQL",
|
||||
"url": "/browser/collation/sql/",
|
||||
"is_positive_test": true,
|
||||
"inventory_data": {
|
||||
"server_min_version": 160000,
|
||||
"skip_msg": "Get Collation SQL are not supported by PG 16.0 and below."
|
||||
},
|
||||
"mocking_required": false,
|
||||
"mock_data": {},
|
||||
"expected_data": {
|
||||
@ -429,10 +405,6 @@
|
||||
"name": "Get collation msql: With existing collation id.",
|
||||
"url": "/browser/collation/msql/",
|
||||
"is_positive_test": true,
|
||||
"inventory_data": {
|
||||
"server_min_version": 160000,
|
||||
"skip_msg": "Get collation msql are not supported by PG 16.0 and below."
|
||||
},
|
||||
"msql": true,
|
||||
"mocking_required": false,
|
||||
"mock_data": {},
|
||||
|
Loading…
Reference in New Issue
Block a user