@pgpm/metaschema-schema 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,13 @@ BEGIN;
7
7
 
8
8
  CREATE UNIQUE INDEX databases_field_uniq_names_idx ON metaschema_public.field (
9
9
  -- strip out any _id, etc., so that if you do create one and make foreign key relation, there is no conflict
10
- table_id, DECODE(MD5(LOWER(regexp_replace(name, '^(.+?)(_row_id|_id|_uuid|_fk|_pk)$', '\1', 'i'))), 'hex')
10
+ -- only apply normalization to uuid fields (FK candidates) to avoid false collisions on text fields like current_role/current_role_id
11
+ table_id, DECODE(MD5(LOWER(
12
+ CASE
13
+ WHEN type = 'uuid' THEN regexp_replace(name, '^(.+?)(_row_id|_id|_uuid|_fk|_pk)$', '\1', 'i')
14
+ ELSE name
15
+ END
16
+ )), 'hex')
11
17
  );
12
18
 
13
19
  COMMIT;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pgpm/metaschema-schema",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Database metadata utilities and introspection functions",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "contributors": [
@@ -37,5 +37,5 @@
37
37
  "bugs": {
38
38
  "url": "https://github.com/constructive-io/pgpm-modules/issues"
39
39
  },
40
- "gitHead": "3b2260bf7640d7194f237d556c7e5033bc7a9405"
40
+ "gitHead": "03bf5866d961bfdfc02fe6dc1778ed8283373f43"
41
41
  }
@@ -224,7 +224,7 @@ CREATE INDEX field_database_id_idx ON metaschema_public.field (database_id);
224
224
 
225
225
  COMMENT ON COLUMN metaschema_public.field.default_value IS '@sqlExpression';
226
226
 
227
- CREATE UNIQUE INDEX databases_field_uniq_names_idx ON metaschema_public.field (table_id, (decode(md5(lower(regexp_replace(name, '^(.+?)(_row_id|_id|_uuid|_fk|_pk)$', E'\\1', 'i'))), 'hex')));
227
+ CREATE UNIQUE INDEX databases_field_uniq_names_idx ON metaschema_public.field (table_id, (decode(md5(lower(CASE WHEN type = 'uuid' THEN regexp_replace(name, '^(.+?)(_row_id|_id|_uuid|_fk|_pk)$', E'\\1', 'i') ELSE name END)), 'hex')));
228
228
 
229
229
  CREATE TABLE metaschema_public.foreign_key_constraint (
230
230
  id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
@@ -579,4 +579,4 @@ COMMENT ON CONSTRAINT db_fkey ON metaschema_public.unique_constraint IS '@omit m
579
579
 
580
580
  CREATE INDEX unique_constraint_table_id_idx ON metaschema_public.unique_constraint (table_id);
581
581
 
582
- CREATE INDEX unique_constraint_database_id_idx ON metaschema_public.unique_constraint (database_id);
582
+ CREATE INDEX unique_constraint_database_id_idx ON metaschema_public.unique_constraint (database_id);