@axinom/mosaic-db-common 0.9.0 → 0.10.0-rc.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.
|
@@ -79,7 +79,7 @@ $$;
|
|
|
79
79
|
|
|
80
80
|
-- creation method to help on consistently create UNIQUE constraint in an idempotent way
|
|
81
81
|
-- constraintName: unique name for this constraint. If value is NULL then a name will be generated from the table name
|
|
82
|
-
CREATE OR REPLACE FUNCTION ax_define.
|
|
82
|
+
CREATE OR REPLACE FUNCTION ax_define.define_multitenancy_unique_field_constraint(fieldName text, tableName text, schemaName text, constraintName text default NULL) RETURNS void
|
|
83
83
|
LANGUAGE plpgsql
|
|
84
84
|
AS $$
|
|
85
85
|
BEGIN
|
|
@@ -125,6 +125,21 @@ BEGIN
|
|
|
125
125
|
END;
|
|
126
126
|
$$;
|
|
127
127
|
|
|
128
|
+
-- creation method to help on consistently create PRIMARY KEY which includes tenant/env
|
|
129
|
+
-- constraintName: unique name for this constraint. If value is NULL then a name will be generated from the table name
|
|
130
|
+
CREATE OR REPLACE FUNCTION ax_define.define_multitenancy_primary_key(fieldNames text, tableName text, schemaName text, constraintName text default NULL) RETURNS void
|
|
131
|
+
LANGUAGE plpgsql
|
|
132
|
+
AS $$
|
|
133
|
+
BEGIN
|
|
134
|
+
SELECT COALESCE(constraintName, tableName || '_pkey') INTO constraintName;
|
|
135
|
+
IF LENGTH(constraintName) > 63 THEN
|
|
136
|
+
perform ax_utils.raise_error('Invalid parameters provided to "ax_define.define_multitenancy_primary_key". Constraint name "%s" exceeds 63 bytes. If the auto-generated name exceeds 63 bytes then a "constraintName" argument must be provided.', 'SETUP', constraintName);
|
|
137
|
+
END IF;
|
|
138
|
+
EXECUTE 'ALTER TABLE ' || schemaName || '.' || tableName || ' DROP CONSTRAINT IF EXISTS ' || constraintName || ';';
|
|
139
|
+
EXECUTE 'ALTER TABLE ' || schemaName || '.' || tableName || ' ADD CONSTRAINT ' || constraintName || ' PRIMARY KEY (' || fieldNames || ',tenant_id, environment_id);';
|
|
140
|
+
END;
|
|
141
|
+
$$;
|
|
142
|
+
|
|
128
143
|
-- creation method to help on consistently create "normal" indexes in an idempotent way for a single field on a multitenancy table
|
|
129
144
|
-- indexName: unique name for this index. If value is NULL then a name will be generated from the table & field names
|
|
130
145
|
CREATE OR REPLACE FUNCTION ax_define.define_multitenancy_index(fieldName text, tableName text, schemaName text, indexName text default NULL) RETURNS void
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-db-common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0-rc.1",
|
|
4
4
|
"description": "This library encapsulates database-related functionality to develop Mosaic based services.",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "e05baab26ad39306f4b06d4e219db0a98a26a5e4"
|
|
49
49
|
}
|