@opengis/fastify-table 1.2.12 → 1.2.13

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.
Files changed (66) hide show
  1. package/README.md +86 -86
  2. package/index.js +79 -79
  3. package/package.json +1 -1
  4. package/server/migrations/0.sql +84 -84
  5. package/server/migrations/cls.sql +39 -39
  6. package/server/migrations/properties.sql +184 -184
  7. package/server/migrations/template.sql +34 -34
  8. package/server/migrations/users.sql +175 -175
  9. package/server/plugins/cron/funcs/addCron.js +130 -130
  10. package/server/plugins/cron/index.js +6 -6
  11. package/server/plugins/crud/funcs/dataDelete.js +24 -24
  12. package/server/plugins/crud/funcs/dataInsert.js +53 -53
  13. package/server/plugins/crud/funcs/dataUpdate.js +65 -65
  14. package/server/plugins/crud/funcs/getOpt.js +13 -13
  15. package/server/plugins/crud/funcs/setOpt.js +21 -21
  16. package/server/plugins/crud/funcs/setToken.js +44 -44
  17. package/server/plugins/crud/funcs/utils/getFolder.js +10 -10
  18. package/server/plugins/crud/funcs/utils/logChanges.js +118 -118
  19. package/server/plugins/crud/index.js +23 -23
  20. package/server/plugins/hook/index.js +8 -8
  21. package/server/plugins/logger/errorStatus.js +19 -19
  22. package/server/plugins/logger/index.js +21 -21
  23. package/server/plugins/migration/exec.migrations.js +37 -37
  24. package/server/plugins/migration/index.js +7 -7
  25. package/server/plugins/pg/pgClients.js +21 -21
  26. package/server/plugins/policy/index.js +12 -12
  27. package/server/plugins/policy/sqlInjection.js +33 -33
  28. package/server/plugins/redis/client.js +8 -8
  29. package/server/plugins/redis/funcs/redisClients.js +3 -3
  30. package/server/plugins/redis/index.js +17 -17
  31. package/server/plugins/table/funcs/addTemplateDir.js +8 -8
  32. package/server/plugins/table/funcs/getFilterSQL/index.js +96 -96
  33. package/server/plugins/table/funcs/getFilterSQL/util/formatValue.js +179 -179
  34. package/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +13 -13
  35. package/server/plugins/table/funcs/getFilterSQL/util/getFilterQuery.js +66 -66
  36. package/server/plugins/table/funcs/getFilterSQL/util/getOptimizedQuery.js +12 -12
  37. package/server/plugins/table/funcs/getFilterSQL/util/getTableSql.js +34 -34
  38. package/server/plugins/table/funcs/getTemplates.js +19 -19
  39. package/server/plugins/table/funcs/gisIRColumn.js +82 -82
  40. package/server/plugins/table/funcs/loadTemplate.js +1 -1
  41. package/server/plugins/table/funcs/loadTemplatePath.js +1 -1
  42. package/server/plugins/table/funcs/metaFormat/getSelectVal.js +50 -50
  43. package/server/plugins/table/funcs/metaFormat/index.js +45 -45
  44. package/server/plugins/table/funcs/userTemplateDir.js +1 -1
  45. package/server/plugins/table/index.js +13 -13
  46. package/server/plugins/util/index.js +7 -7
  47. package/server/routes/cron/index.js +14 -14
  48. package/server/routes/crud/controllers/deleteCrud.js +39 -39
  49. package/server/routes/crud/controllers/table.js +91 -91
  50. package/server/routes/logger/controllers/logger.file.js +92 -92
  51. package/server/routes/logger/controllers/utils/checkUserAccess.js +19 -19
  52. package/server/routes/logger/controllers/utils/getRootDir.js +26 -26
  53. package/server/routes/logger/index.js +17 -17
  54. package/server/routes/properties/controllers/properties.add.js +55 -55
  55. package/server/routes/properties/controllers/properties.get.js +17 -17
  56. package/server/routes/properties/index.js +16 -16
  57. package/server/routes/table/controllers/data.js +172 -169
  58. package/server/routes/table/controllers/filter.js +67 -67
  59. package/server/routes/table/controllers/form.js +42 -42
  60. package/server/routes/table/controllers/search.js +74 -74
  61. package/server/routes/table/controllers/suggest.js +166 -166
  62. package/server/routes/table/index.js +29 -29
  63. package/server/routes/table/schema.js +64 -64
  64. package/server/routes/util/controllers/status.monitor.js +8 -8
  65. package/server/routes/util/index.js +11 -11
  66. package/utils.js +129 -129
package/README.md CHANGED
@@ -1,87 +1,87 @@
1
- # fastify-table
2
-
3
- <!-- ![alt text](https://cdn.softpro.ua/data/npm/admin/opengis-admin.png) -->
4
-
5
- [![NPM version](https://img.shields.io/npm/v/@opengis/fastify-table?style=plain)](https://www.npmjs.com/package/@opengis/fastify-table)
6
- [![NPM last update](https://img.shields.io/npm/last-update/@opengis/fastify-table?style=plain)]()
7
- [![NPM downloads](https://img.shields.io/npm/dw/@opengis/fastify-table?style=plain)]()
8
- [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=plain)](http://standardjs.com/)
9
-
10
- This is a backend toolkit for database management and more.
11
-
12
- ### Why fastify-table?
13
-
14
- - **Logger** - Monitoring user activity and system status.
15
- - **Redis cache** - Optimizes web page rendering for lightning-fast performance.
16
- - **Secure** - Ensures protection against XSS attacks in queries.
17
- - **SQL Migration** - Automatically adds all necessary tables to your project's database.
18
-
19
-
20
- ### Features
21
-
22
- - CRUD
23
- - cron
24
- - Logger
25
- - Redis
26
- - pg
27
-
28
- ---
29
-
30
- ### Install
31
-
32
- ```bash
33
- npm i @opengis/fastify-table
34
- ```
35
-
36
- ### Usage
37
-
38
- ```js
39
- fastify.register(import('@opengis/fastify-table'), config);
40
- ```
41
-
42
- ---
43
-
44
- ### Documenation
45
-
46
- For a detailed understanding `fastify-table`, its features, and how to use them, refer to our [Documentation](https://apidocs.softpro.ua/fastify-table/).
47
-
48
- ---
49
-
50
- ### Technology stack
51
-
52
- <a href="https://fastify.dev/" target="_blank">
53
- <img src="https://img.shields.io/badge/Fastify-323330?style=for-the-badge&logo=fastify" /></a>
54
-
55
- <a href="https://www.postgresql.org/" target="_blank">
56
- <img src="https://img.shields.io/badge/PostgreSQL-323330?style=for-the-badge&logo=postgresql&logoColor=white" /></a>
57
-
58
- <a href="https://redis.io/" target="_blank">
59
- <img src="https://img.shields.io/badge/redis-323330.svg?&style=for-the-badge&logo=redis&logoColor=" /></a>
60
-
61
- <a href="https://www.npmjs.com/package/pino" target="_blank">
62
- <img src="https://img.shields.io/badge/pino-323330.svg?&style=for-the-badge&logo=pino&logoColor=" /></a>
63
-
64
- ---
65
-
66
- ### Contribute
67
-
68
- Feel free to contact us through our website [SOFTPRO.UA](https://softpro.ua) or email <info@softpro.ua>
69
-
70
- - Report bugs
71
- - Share your ideas
72
- - Ask questions
73
-
74
- ### Follow Us
75
-
76
- [Official site](https://softpro.ua)
77
-
78
- <p>
79
- <a href="https://www.instagram.com/gissoftpro/" target="_blank"><img src="https://cdn.softpro.ua/data/npm/instagram.png" alt="Softpro Instagram" title="oftpro Instagram"></a>&nbsp;&nbsp;
80
- <a href="https://www.facebook.com/gissoftpro" target="_blank"><img src="https://cdn.softpro.ua/data/npm/facebook.png" alt="Softpro Facebook" title="Softpro Facebook"></a>&nbsp;&nbsp;
81
- <a href="https://t.me/softprogis" target="_blank"><img src="https://cdn.softpro.ua/data/npm/telegram.png" alt="Softpro Telegram" title="Softpro Telegram"></a>&nbsp;&nbsp;
82
- <a href="https://www.linkedin.com/in/softpro-ukraine-a8876b282/recent-activity/all/" target="_blank"><img src="https://cdn.softpro.ua/data/npm/social/linkedin.png" alt="Softpro Linkedin" title="Softpro LinkedIn"></a>&nbsp;&nbsp;
83
- </p>
84
-
85
- ### License
86
-
1
+ # fastify-table
2
+
3
+ <!-- ![alt text](https://cdn.softpro.ua/data/npm/admin/opengis-admin.png) -->
4
+
5
+ [![NPM version](https://img.shields.io/npm/v/@opengis/fastify-table?style=plain)](https://www.npmjs.com/package/@opengis/fastify-table)
6
+ [![NPM last update](https://img.shields.io/npm/last-update/@opengis/fastify-table?style=plain)]()
7
+ [![NPM downloads](https://img.shields.io/npm/dw/@opengis/fastify-table?style=plain)]()
8
+ [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=plain)](http://standardjs.com/)
9
+
10
+ This is a backend toolkit for database management and more.
11
+
12
+ ### Why fastify-table?
13
+
14
+ - **Logger** - Monitoring user activity and system status.
15
+ - **Redis cache** - Optimizes web page rendering for lightning-fast performance.
16
+ - **Secure** - Ensures protection against XSS attacks in queries.
17
+ - **SQL Migration** - Automatically adds all necessary tables to your project's database.
18
+
19
+
20
+ ### Features
21
+
22
+ - CRUD
23
+ - cron
24
+ - Logger
25
+ - Redis
26
+ - pg
27
+
28
+ ---
29
+
30
+ ### Install
31
+
32
+ ```bash
33
+ npm i @opengis/fastify-table
34
+ ```
35
+
36
+ ### Usage
37
+
38
+ ```js
39
+ fastify.register(import('@opengis/fastify-table'), config);
40
+ ```
41
+
42
+ ---
43
+
44
+ ### Documenation
45
+
46
+ For a detailed understanding `fastify-table`, its features, and how to use them, refer to our [Documentation](https://apidocs.softpro.ua/fastify-table/).
47
+
48
+ ---
49
+
50
+ ### Technology stack
51
+
52
+ <a href="https://fastify.dev/" target="_blank">
53
+ <img src="https://img.shields.io/badge/Fastify-323330?style=for-the-badge&logo=fastify" /></a>
54
+
55
+ <a href="https://www.postgresql.org/" target="_blank">
56
+ <img src="https://img.shields.io/badge/PostgreSQL-323330?style=for-the-badge&logo=postgresql&logoColor=white" /></a>
57
+
58
+ <a href="https://redis.io/" target="_blank">
59
+ <img src="https://img.shields.io/badge/redis-323330.svg?&style=for-the-badge&logo=redis&logoColor=" /></a>
60
+
61
+ <a href="https://www.npmjs.com/package/pino" target="_blank">
62
+ <img src="https://img.shields.io/badge/pino-323330.svg?&style=for-the-badge&logo=pino&logoColor=" /></a>
63
+
64
+ ---
65
+
66
+ ### Contribute
67
+
68
+ Feel free to contact us through our website [SOFTPRO.UA](https://softpro.ua) or email <info@softpro.ua>
69
+
70
+ - Report bugs
71
+ - Share your ideas
72
+ - Ask questions
73
+
74
+ ### Follow Us
75
+
76
+ [Official site](https://softpro.ua)
77
+
78
+ <p>
79
+ <a href="https://www.instagram.com/gissoftpro/" target="_blank"><img src="https://cdn.softpro.ua/data/npm/instagram.png" alt="Softpro Instagram" title="oftpro Instagram"></a>&nbsp;&nbsp;
80
+ <a href="https://www.facebook.com/gissoftpro" target="_blank"><img src="https://cdn.softpro.ua/data/npm/facebook.png" alt="Softpro Facebook" title="Softpro Facebook"></a>&nbsp;&nbsp;
81
+ <a href="https://t.me/softprogis" target="_blank"><img src="https://cdn.softpro.ua/data/npm/telegram.png" alt="Softpro Telegram" title="Softpro Telegram"></a>&nbsp;&nbsp;
82
+ <a href="https://www.linkedin.com/in/softpro-ukraine-a8876b282/recent-activity/all/" target="_blank"><img src="https://cdn.softpro.ua/data/npm/social/linkedin.png" alt="Softpro Linkedin" title="Softpro LinkedIn"></a>&nbsp;&nbsp;
83
+ </p>
84
+
85
+ ### License
86
+
87
87
  Copyright © SOFTPRO. All rights reserved.
package/index.js CHANGED
@@ -1,79 +1,79 @@
1
- import path from 'node:path';
2
- import fp from 'fastify-plugin';
3
- import { fileURLToPath } from 'node:url';
4
-
5
- import config from './config.js';
6
-
7
- // plugins
8
- import cronPlugin from './server/plugins/cron/index.js';
9
- import crudPlugin from './server/plugins/crud/index.js';
10
- // hook, logger, migration - utils only
11
- import pgPlugin from './server/plugins/pg/index.js';
12
- import policyPlugin from './server/plugins/policy/index.js';
13
- import redisPlugin from './server/plugins/redis/index.js';
14
- import tablePlugin from './server/plugins/table/index.js';
15
- import utilPlugin from './server/plugins/util/index.js';
16
- import loggerPlugin from './server/plugins/logger/index.js';
17
-
18
- // routes
19
- import cronRoutes from './server/routes/cron/index.js';
20
- import crudRoutes from './server/routes/crud/index.js';
21
- import loggerRoutes from './server/routes/logger/index.js';
22
- import propertiesRoutes from './server/routes/properties/index.js';
23
- import tableRoutes from './server/routes/table/index.js';
24
- import utilRoutes from './server/routes/util/index.js';
25
-
26
- import {
27
- addTemplateDir, execMigrations,
28
- } from './utils.js';
29
-
30
- async function plugin(fastify, opt) {
31
- config.pg = opt.pg;
32
- config.redis = opt.redis;
33
- config.root = opt.root;
34
- config.mapServerRoot = opt.mapServerRoot;
35
-
36
- // independent npm start / unit test
37
- if (!fastify.config) {
38
- fastify.decorate('config', config);
39
- }
40
-
41
- fastify.register(import('@fastify/sensible'), {
42
- errorHandler: false,
43
- });
44
-
45
- fastify.register(import('@fastify/url-data'), {
46
- errorHandler: false,
47
- });
48
-
49
- fastify.register(import('@opengis/fastify-hb'));
50
-
51
- const filename = fileURLToPath(import.meta.url);
52
- const cwd = path.dirname(filename);
53
-
54
- // core migrations (second argument for core only)
55
- execMigrations(path.join(cwd, 'server/migrations'), true).catch(err => console.log(err));
56
-
57
- // core templates && cls
58
- config.templates?.forEach(el => addTemplateDir(el));
59
- addTemplateDir(path.join(cwd, 'module/core'));
60
-
61
- // plugins / utils / funcs
62
- policyPlugin(fastify);
63
- redisPlugin(fastify);
64
- await pgPlugin(fastify, opt);
65
- tablePlugin(fastify, opt);
66
- crudPlugin(fastify, opt);
67
- utilPlugin(fastify, opt);
68
- cronPlugin(fastify, opt);
69
- loggerPlugin(fastify, opt);
70
-
71
- // routes / api
72
- cronRoutes(fastify, opt);
73
- crudRoutes(fastify, opt);
74
- loggerRoutes(fastify, opt);
75
- propertiesRoutes(fastify, opt);
76
- tableRoutes(fastify, opt);
77
- utilRoutes(fastify, opt);
78
- }
79
- export default fp(plugin);
1
+ import path from 'node:path';
2
+ import fp from 'fastify-plugin';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ import config from './config.js';
6
+
7
+ // plugins
8
+ import cronPlugin from './server/plugins/cron/index.js';
9
+ import crudPlugin from './server/plugins/crud/index.js';
10
+ // hook, logger, migration - utils only
11
+ import pgPlugin from './server/plugins/pg/index.js';
12
+ import policyPlugin from './server/plugins/policy/index.js';
13
+ import redisPlugin from './server/plugins/redis/index.js';
14
+ import tablePlugin from './server/plugins/table/index.js';
15
+ import utilPlugin from './server/plugins/util/index.js';
16
+ import loggerPlugin from './server/plugins/logger/index.js';
17
+
18
+ // routes
19
+ import cronRoutes from './server/routes/cron/index.js';
20
+ import crudRoutes from './server/routes/crud/index.js';
21
+ import loggerRoutes from './server/routes/logger/index.js';
22
+ import propertiesRoutes from './server/routes/properties/index.js';
23
+ import tableRoutes from './server/routes/table/index.js';
24
+ import utilRoutes from './server/routes/util/index.js';
25
+
26
+ import {
27
+ addTemplateDir, execMigrations,
28
+ } from './utils.js';
29
+
30
+ async function plugin(fastify, opt) {
31
+ config.pg = opt.pg;
32
+ config.redis = opt.redis;
33
+ config.root = opt.root;
34
+ config.mapServerRoot = opt.mapServerRoot;
35
+
36
+ // independent npm start / unit test
37
+ if (!fastify.config) {
38
+ fastify.decorate('config', config);
39
+ }
40
+
41
+ fastify.register(import('@fastify/sensible'), {
42
+ errorHandler: false,
43
+ });
44
+
45
+ fastify.register(import('@fastify/url-data'), {
46
+ errorHandler: false,
47
+ });
48
+
49
+ fastify.register(import('@opengis/fastify-hb'));
50
+
51
+ const filename = fileURLToPath(import.meta.url);
52
+ const cwd = path.dirname(filename);
53
+
54
+ // core migrations (second argument for core only)
55
+ execMigrations(path.join(cwd, 'server/migrations'), true).catch(err => console.log(err));
56
+
57
+ // core templates && cls
58
+ config.templates?.forEach(el => addTemplateDir(el));
59
+ addTemplateDir(path.join(cwd, 'module/core'));
60
+
61
+ // plugins / utils / funcs
62
+ policyPlugin(fastify);
63
+ redisPlugin(fastify);
64
+ await pgPlugin(fastify, opt);
65
+ tablePlugin(fastify, opt);
66
+ crudPlugin(fastify, opt);
67
+ utilPlugin(fastify, opt);
68
+ cronPlugin(fastify, opt);
69
+ loggerPlugin(fastify, opt);
70
+
71
+ // routes / api
72
+ cronRoutes(fastify, opt);
73
+ crudRoutes(fastify, opt);
74
+ loggerRoutes(fastify, opt);
75
+ propertiesRoutes(fastify, opt);
76
+ tableRoutes(fastify, opt);
77
+ utilRoutes(fastify, opt);
78
+ }
79
+ export default fp(plugin);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -1,84 +1,84 @@
1
- -- fix error if function exists and return type not text i.e bigint
2
-
3
- do $$
4
-
5
- declare
6
- m record;
7
- _pk text;
8
- _tables json;
9
- _returnType text;
10
-
11
- begin
12
-
13
- select format_type(p.prorettype, null) as return_type
14
- from pg_proc p
15
- where p.proname = 'next_id'
16
- and p.pronamespace = 'public'::regnamespace into _returnType;
17
-
18
- if (_returnType != 'text') then
19
- raise notice 'default reassign start: % -> text', _returnType;
20
-
21
- CREATE EXTENSION if not exists "uuid-ossp";
22
-
23
- SELECT json_object_agg(a.attrelid::regclass, a.attname)
24
- FROM pg_catalog.pg_attribute a
25
- LEFT JOIN pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
26
- WHERE NOT a.attisdropped -- no dropped (dead) columns
27
- AND a.attnum > 0 -- no system columns
28
- AND pg_get_expr(d.adbin, d.adrelid) = 'next_id()' into _tables;
29
-
30
- FOR m in (select json_object_keys(_tables) as table) loop
31
- _pk = _tables->>m.table;
32
- raise notice 'drop default: %,%', m.table, _pk;
33
- EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default null;');
34
- end loop;
35
-
36
- DROP FUNCTION IF EXISTS next_id();
37
-
38
- /* CREATE EXTENSION if not exists "uuid-ossp";
39
- ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
40
-
41
- CREATE OR REPLACE FUNCTION next_id()
42
- RETURNS text AS
43
- $BODY$
44
- DECLARE
45
-
46
- BEGIN
47
- -- return replace(public.uuid_generate_v4()::text, '-', '');
48
- -- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
49
- return encode(public.gen_random_bytes(6), 'hex');
50
- END;
51
- $BODY$
52
- LANGUAGE plpgsql VOLATILE
53
- COST 100;
54
-
55
- FOR m in (select json_object_keys(_tables) as table) loop
56
- _pk = _tables->>m.table;
57
- raise notice 'reassign default: %, %', m.table, _pk;
58
- EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default next_id();');
59
- end loop;
60
-
61
- raise notice 'reassign default finish: %', _tables;
62
-
63
- else
64
- raise notice 'skip default reassign';
65
-
66
- /* CREATE EXTENSION if not exists "uuid-ossp";
67
- ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
68
-
69
- CREATE OR REPLACE FUNCTION next_id()
70
- RETURNS text AS
71
- $BODY$
72
- DECLARE
73
-
74
- BEGIN
75
- -- return replace(public.uuid_generate_v4()::text, '-', '');
76
- -- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
77
- return encode(public.gen_random_bytes(6), 'hex');
78
- END;
79
- $BODY$
80
- LANGUAGE plpgsql VOLATILE
81
- COST 100;
82
- end if;
83
-
84
- end $$
1
+ -- fix error if function exists and return type not text i.e bigint
2
+
3
+ do $$
4
+
5
+ declare
6
+ m record;
7
+ _pk text;
8
+ _tables json;
9
+ _returnType text;
10
+
11
+ begin
12
+
13
+ select format_type(p.prorettype, null) as return_type
14
+ from pg_proc p
15
+ where p.proname = 'next_id'
16
+ and p.pronamespace = 'public'::regnamespace into _returnType;
17
+
18
+ if (_returnType != 'text') then
19
+ raise notice 'default reassign start: % -> text', _returnType;
20
+
21
+ CREATE EXTENSION if not exists "uuid-ossp";
22
+
23
+ SELECT json_object_agg(a.attrelid::regclass, a.attname)
24
+ FROM pg_catalog.pg_attribute a
25
+ LEFT JOIN pg_catalog.pg_attrdef d ON (a.attrelid, a.attnum) = (d.adrelid, d.adnum)
26
+ WHERE NOT a.attisdropped -- no dropped (dead) columns
27
+ AND a.attnum > 0 -- no system columns
28
+ AND pg_get_expr(d.adbin, d.adrelid) = 'next_id()' into _tables;
29
+
30
+ FOR m in (select json_object_keys(_tables) as table) loop
31
+ _pk = _tables->>m.table;
32
+ raise notice 'drop default: %,%', m.table, _pk;
33
+ EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default null;');
34
+ end loop;
35
+
36
+ DROP FUNCTION IF EXISTS next_id();
37
+
38
+ /* CREATE EXTENSION if not exists "uuid-ossp";
39
+ ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
40
+
41
+ CREATE OR REPLACE FUNCTION next_id()
42
+ RETURNS text AS
43
+ $BODY$
44
+ DECLARE
45
+
46
+ BEGIN
47
+ -- return replace(public.uuid_generate_v4()::text, '-', '');
48
+ -- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
49
+ return encode(public.gen_random_bytes(6), 'hex');
50
+ END;
51
+ $BODY$
52
+ LANGUAGE plpgsql VOLATILE
53
+ COST 100;
54
+
55
+ FOR m in (select json_object_keys(_tables) as table) loop
56
+ _pk = _tables->>m.table;
57
+ raise notice 'reassign default: %, %', m.table, _pk;
58
+ EXECUTE('alter table '|| m.table || ' alter column ' || _pk || ' set default next_id();');
59
+ end loop;
60
+
61
+ raise notice 'reassign default finish: %', _tables;
62
+
63
+ else
64
+ raise notice 'skip default reassign';
65
+
66
+ /* CREATE EXTENSION if not exists "uuid-ossp";
67
+ ALTER EXTENSION "uuid-ossp" SET SCHEMA public; */
68
+
69
+ CREATE OR REPLACE FUNCTION next_id()
70
+ RETURNS text AS
71
+ $BODY$
72
+ DECLARE
73
+
74
+ BEGIN
75
+ -- return replace(public.uuid_generate_v4()::text, '-', '');
76
+ -- return replace(gen_random_uuid()::text, '-', ''); -- native from postgres 13 onward
77
+ return encode(public.gen_random_bytes(6), 'hex');
78
+ END;
79
+ $BODY$
80
+ LANGUAGE plpgsql VOLATILE
81
+ COST 100;
82
+ end if;
83
+
84
+ end $$
@@ -1,39 +1,39 @@
1
- create schema if not exists admin;
2
-
3
- CREATE TABLE if not exists admin.cls();
4
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS clsid text;
5
- ALTER TABLE admin.cls DROP CONSTRAINT IF EXISTS admin_cls_pkey;
6
- ALTER TABLE admin.cls DROP CONSTRAINT IF EXISTS admin_cls_unique;
7
-
8
- ALTER TABLE admin.cls ALTER COLUMN clsid SET NOT NULL;
9
- ALTER TABLE admin.cls ALTER COLUMN clsid SET DEFAULT next_id();
10
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS name text;
11
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS data text;
12
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS type text;
13
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS code text;
14
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS parent text;
15
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS ua text;
16
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS en text;
17
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS module text;
18
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS files json;
19
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS cdate timestamp without time zone;
20
- ALTER TABLE admin.cls ALTER COLUMN cdate SET DEFAULT (now())::timestamp without time zone;
21
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS editor_id text;
22
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
23
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS uid text;
24
- ALTER TABLE admin.cls ALTER COLUMN uid SET NOT NULL;
25
- ALTER TABLE admin.cls ALTER COLUMN uid SET DEFAULT '1'::text;
26
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS icon text;
27
- ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS color text;
28
-
29
- ALTER TABLE admin.cls ADD CONSTRAINT admin_cls_pkey PRIMARY KEY (clsid);
30
- ALTER TABLE admin.cls ADD CONSTRAINT admin_cls_unique UNIQUE (code, parent);
31
-
32
- COMMENT ON COLUMN admin.cls.name IS 'Назва';
33
- COMMENT ON COLUMN admin.cls.type IS 'Тип';
34
- COMMENT ON COLUMN admin.cls.data IS 'SQL';
35
- COMMENT ON COLUMN admin.cls.code IS 'Код';
36
- COMMENT ON COLUMN admin.cls.parent IS 'Назва батьківського об''єкту';
37
- COMMENT ON COLUMN admin.cls.module IS 'Модуль';
38
- COMMENT ON COLUMN admin.cls.icon IS 'Іконка';
39
- COMMENT ON COLUMN admin.cls.color IS 'Колір';
1
+ create schema if not exists admin;
2
+
3
+ CREATE TABLE if not exists admin.cls();
4
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS clsid text;
5
+ ALTER TABLE admin.cls DROP CONSTRAINT IF EXISTS admin_cls_pkey;
6
+ ALTER TABLE admin.cls DROP CONSTRAINT IF EXISTS admin_cls_unique;
7
+
8
+ ALTER TABLE admin.cls ALTER COLUMN clsid SET NOT NULL;
9
+ ALTER TABLE admin.cls ALTER COLUMN clsid SET DEFAULT next_id();
10
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS name text;
11
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS data text;
12
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS type text;
13
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS code text;
14
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS parent text;
15
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS ua text;
16
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS en text;
17
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS module text;
18
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS files json;
19
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS cdate timestamp without time zone;
20
+ ALTER TABLE admin.cls ALTER COLUMN cdate SET DEFAULT (now())::timestamp without time zone;
21
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS editor_id text;
22
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS editor_date timestamp without time zone;
23
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS uid text;
24
+ ALTER TABLE admin.cls ALTER COLUMN uid SET NOT NULL;
25
+ ALTER TABLE admin.cls ALTER COLUMN uid SET DEFAULT '1'::text;
26
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS icon text;
27
+ ALTER TABLE admin.cls ADD COLUMN IF NOT EXISTS color text;
28
+
29
+ ALTER TABLE admin.cls ADD CONSTRAINT admin_cls_pkey PRIMARY KEY (clsid);
30
+ ALTER TABLE admin.cls ADD CONSTRAINT admin_cls_unique UNIQUE (code, parent);
31
+
32
+ COMMENT ON COLUMN admin.cls.name IS 'Назва';
33
+ COMMENT ON COLUMN admin.cls.type IS 'Тип';
34
+ COMMENT ON COLUMN admin.cls.data IS 'SQL';
35
+ COMMENT ON COLUMN admin.cls.code IS 'Код';
36
+ COMMENT ON COLUMN admin.cls.parent IS 'Назва батьківського об''єкту';
37
+ COMMENT ON COLUMN admin.cls.module IS 'Модуль';
38
+ COMMENT ON COLUMN admin.cls.icon IS 'Іконка';
39
+ COMMENT ON COLUMN admin.cls.color IS 'Колір';