@opengis/fastify-table 2.4.0 → 2.4.2

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 (86) hide show
  1. package/README.md +86 -86
  2. package/dist/functions.js +20 -20
  3. package/dist/module/core/cls/constraint_action.json +9 -9
  4. package/dist/module/core/cls/constraint_matchtype.json +5 -5
  5. package/dist/module/core/cls/constraint_type_full.json +17 -17
  6. package/dist/module/core/cls/core.user_type.json +13 -13
  7. package/dist/module/core/pt/schemaItem.pt.hbs +17 -17
  8. package/dist/script/adduser +14 -14
  9. package/dist/script/dump.js +48 -48
  10. package/dist/script/dump.ts +216 -216
  11. package/dist/script/migrate.ts +41 -41
  12. package/dist/server/helpers/core/badge.js +1 -1
  13. package/dist/server/helpers/list/descriptionList.js +8 -8
  14. package/dist/server/helpers/list/tableList.js +4 -4
  15. package/dist/server/helpers/list/utils/button.js +1 -1
  16. package/dist/server/helpers/list/utils/buttonDel.js +3 -3
  17. package/dist/server/helpers/list/utils/buttonEdit.js +3 -3
  18. package/dist/server/helpers/utils/button.js +1 -1
  19. package/dist/server/helpers/utils/buttonAdd.js +15 -15
  20. package/dist/server/helpers/utils/buttonDel.js +11 -11
  21. package/dist/server/helpers/utils/buttonEdit.js +3 -3
  22. package/dist/server/migrations/0.sql +99 -99
  23. package/dist/server/migrations/cls.sql +105 -105
  24. package/dist/server/migrations/context.sql +136 -136
  25. package/dist/server/migrations/oauth.sql +79 -79
  26. package/dist/server/migrations/properties.sql +115 -115
  27. package/dist/server/migrations/roles.sql +195 -195
  28. package/dist/server/migrations/template.sql +43 -43
  29. package/dist/server/migrations/users.sql +151 -151
  30. package/dist/server/plugins/access/funcs/getUserPermissions.js +7 -7
  31. package/dist/server/plugins/auth/funcs/authorizeUser.js +4 -4
  32. package/dist/server/plugins/auth/funcs/getQuery.js +20 -20
  33. package/dist/server/plugins/crud/funcs/dataUpdate.js +7 -7
  34. package/dist/server/plugins/crud/funcs/getAccess.js +14 -14
  35. package/dist/server/plugins/crud/funcs/utils/getInsertQuery.js +6 -6
  36. package/dist/server/plugins/crud/funcs/utils/logChanges.js +18 -18
  37. package/dist/server/plugins/grpc/utils/convertp.proto +136 -136
  38. package/dist/server/plugins/grpc/utils/htmlTemplate.js +10 -10
  39. package/dist/server/plugins/grpc/utils/office2pdf.proto +13 -13
  40. package/dist/server/plugins/logger/errorMessage.d.ts.map +1 -1
  41. package/dist/server/plugins/logger/errorMessage.js +3 -0
  42. package/dist/server/plugins/metric/loggerSystem.js +1 -1
  43. package/dist/server/plugins/pg/funcs/autoIndex.js +5 -5
  44. package/dist/server/plugins/pg/funcs/getMeta.js +10 -10
  45. package/dist/server/plugins/pg/funcs/init.js +36 -36
  46. package/dist/server/plugins/sqlite/funcs/init.js +22 -22
  47. package/dist/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +1 -1
  48. package/dist/server/plugins/table/funcs/getSelect.js +1 -1
  49. package/dist/server/plugins/table/funcs/gisIRColumn.js +3 -3
  50. package/dist/server/plugins/usercls/index.js +2 -2
  51. package/dist/server/routes/access/controllers/access.group.js +6 -6
  52. package/dist/server/routes/access/controllers/access.group.post.js +5 -5
  53. package/dist/server/routes/access/controllers/access.interface.js +14 -14
  54. package/dist/server/routes/access/controllers/access.user.js +6 -6
  55. package/dist/server/routes/auth/controllers/2factor/providers/totp.js +5 -5
  56. package/dist/server/routes/auth/controllers/2factor/qrcode.js +1 -1
  57. package/dist/server/routes/auth/controllers/2factor/recovery.js +1 -1
  58. package/dist/server/routes/auth/controllers/2factor/verify.js +1 -1
  59. package/dist/server/routes/auth/controllers/core/getUserInfo.js +33 -33
  60. package/dist/server/routes/auth/controllers/core/passwordRecovery.js +1 -1
  61. package/dist/server/routes/auth/controllers/core/registration.js +2 -2
  62. package/dist/server/routes/auth/controllers/page/login2faTemplate.js +1 -1
  63. package/dist/server/routes/cron/controllers/cronApi.d.ts.map +1 -1
  64. package/dist/server/routes/cron/controllers/cronApi.js +9 -4
  65. package/dist/server/routes/file/controllers/resizeAll.js +6 -6
  66. package/dist/server/routes/grpc/controllers/file2geojson.js +13 -13
  67. package/dist/server/routes/menu/controllers/getMenu.js +9 -9
  68. package/dist/server/routes/notifications/controllers/readNotifications.js +4 -4
  69. package/dist/server/routes/notifications/controllers/userNotifications.js +3 -3
  70. package/dist/server/routes/table/controllers/card.js +1 -1
  71. package/dist/server/routes/table/controllers/filter.js +6 -6
  72. package/dist/server/routes/table/controllers/form.js +1 -1
  73. package/dist/server/routes/table/controllers/getFormByTable.js +6 -6
  74. package/dist/server/routes/table/controllers/suggest.js +3 -3
  75. package/dist/server/routes/table/controllers/tableData.js +2 -2
  76. package/dist/server/routes/table/controllers/tableInfo.js +10 -10
  77. package/dist/server/routes/table/functions/getData.js +13 -13
  78. package/dist/server/routes/widget/controllers/widget.get.js +33 -33
  79. package/dist/server/routes/widget/controllers/widget.set.js +3 -3
  80. package/dist/server/templates/page/2factor-recovery.html +101 -101
  81. package/dist/server/templates/page/2factor.html +140 -140
  82. package/dist/server/templates/page/login.html +90 -90
  83. package/dist/server/templates/page/loginEuSign.html +123 -123
  84. package/dist/server/templates/pt/recovery-codes-email-template.hbs +12 -12
  85. package/dist/server/templates/pt/recovery-password-email-template.html +20 -20
  86. package/package.json +98 -98
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/dist/functions.js CHANGED
@@ -31,7 +31,7 @@ export async function onListen1() {
31
31
  arr.map((item) => item?.ua).indexOf(el?.ua) === idx);
32
32
  const q = `insert into admin.menu(name, ord) values${uniqueList
33
33
  .map((el, i) => `('${el?.ua.replace(/'/g, "''")}', ${i}) `)
34
- .join(",")}
34
+ .join(",")}
35
35
  on conflict (name) do update set ord=excluded.ord, enabled=true returning name, menu_id`;
36
36
  const { rows = [] } = uniqueList.length ? await client.query(q) : {};
37
37
  const menus = rows.reduce((acc, curr) => Object.assign(acc, {
@@ -55,25 +55,25 @@ export async function onListen1() {
55
55
  });
56
56
  }));
57
57
  // console.log(values)
58
- const q1 = `insert into admin.routes(route_id, alias, title, menu_id, table_name, actions, access, query)
58
+ const q1 = `insert into admin.routes(route_id, alias, title, menu_id, table_name, actions, access, query)
59
59
  values ${values
60
60
  .filter((el) => el?.path)
61
- .map((el) => `('${el.path}', ${el.table ? `'${el.table}'` : null},
61
+ .map((el) => `('${el.path}', ${el.table ? `'${el.table}'` : null},
62
62
  ${el.title || el.ua
63
63
  ? `'${(el.title || el.ua).replace(/'/g, "''")}'`
64
- : null},
65
- ${el.menuId ? `'${el.menuId}'` : null}, ${el.table1 ? `'${el.table1}'` : null},
66
- ${el.actions?.length ? `'{ ${el.actions} }'::text[]` : null}, ${el.access ? `'${el.access}'` : null},
64
+ : null},
65
+ ${el.menuId ? `'${el.menuId}'` : null}, ${el.table1 ? `'${el.table1}'` : null},
66
+ ${el.actions?.length ? `'{ ${el.actions} }'::text[]` : null}, ${el.access ? `'${el.access}'` : null},
67
67
  ${el.query ? `'${el.query.replace(/'/g, "''")}'` : "'1=1'"})`)
68
- .join(",")}
69
- on conflict (route_id) do update set menu_id=excluded.menu_id, alias=excluded.alias, title=excluded.title, enabled=true, query=excluded.query,
68
+ .join(",")}
69
+ on conflict (route_id) do update set menu_id=excluded.menu_id, alias=excluded.alias, title=excluded.title, enabled=true, query=excluded.query,
70
70
  table_name=excluded.table_name, actions=excluded.actions, access=excluded.access returning route_id, table_name`;
71
71
  try {
72
72
  console.log("admin/hook routes sql start");
73
- const { rowCount: menuCount } = await client.query(`delete from admin.menu
73
+ const { rowCount: menuCount } = await client.query(`delete from admin.menu
74
74
  where not array[menu_id] <@ $1::text[] and menu_id not in (select menu_id from admin.routes)`, [rows.map((el) => el.menu_id)]);
75
75
  console.log("delete deprecated menus ok", menuCount);
76
- const { rowCount: interfaceCount } = await client.query(`delete from admin.routes
76
+ const { rowCount: interfaceCount } = await client.query(`delete from admin.routes
77
77
  where not array[route_id] <@ $1::text[] and route_id not in (select route_id from admin.role_access)`, [values.filter((el) => el?.path)]);
78
78
  console.log("delete deprecated interfaces ok", interfaceCount);
79
79
  const { rowCount } = values?.length ? await client.query(q1) : {};
@@ -134,9 +134,9 @@ export async function onListen2() {
134
134
  return el.hash;
135
135
  }
136
136
  else if (type === "cls" && loadTemplate?.length && el.update) {
137
- clsQuery.push(`insert into admin.cls(name,type, module,hash) values('${name}','json', '${module?.replace(/'/g, "''")}','${el.hash}');
138
- insert into admin.cls(code,name,parent,icon,color,data)
139
- select value->>'id',value->>'text','${name}',value->>'icon',value->>'color',value->>'data'
137
+ clsQuery.push(`insert into admin.cls(name,type, module,hash) values('${name}','json', '${module?.replace(/'/g, "''")}','${el.hash}');
138
+ insert into admin.cls(code,name,parent,icon,color,data)
139
+ select value->>'id',value->>'text','${name}',value->>'icon',value->>'color',value->>'data'
140
140
  from json_array_elements('${JSON.stringify(loadTemplate).replace(/'/g, "''")}'::json) on conflict (code,parent) do update set color=excluded.color;`);
141
141
  if (config.trace)
142
142
  console.log(name, type, "insert fresh cls");
@@ -224,7 +224,7 @@ export async function afterTable({ table, res = {}, payload: rows = [], user = {
224
224
  !client?.pk?.["admin.custom_column"])
225
225
  return;
226
226
  // admin.custom_column - user column data
227
- const { rows: properties = [] } = await client.query(`select column_id, name, title, format, data from admin.custom_column
227
+ const { rows: properties = [] } = await client.query(`select column_id, name, title, format, data from admin.custom_column
228
228
  where _table and entity=$1 and uid=$2`, [table, uid]);
229
229
  const extraColumnList = properties.map((row) => ({
230
230
  id: row.column_id,
@@ -238,7 +238,7 @@ export async function afterTable({ table, res = {}, payload: rows = [], user = {
238
238
  if (Array.isArray(res?.columns) && res?.columns?.length) {
239
239
  extraColumnList.forEach((col) => res.columns.push(col));
240
240
  }
241
- const { rows: extraData = [] } = await client.query(`select object_id, json_object_agg( property_id, coalesce(value_date::text,value_text) ) as extra from crm.extra_data
241
+ const { rows: extraData = [] } = await client.query(`select object_id, json_object_agg( property_id, coalesce(value_date::text,value_text) ) as extra from crm.extra_data
242
242
  where property_entity=$1 and property_id=any($2) and object_id=any($3) group by object_id`, [
243
243
  table,
244
244
  extraColumnList?.map((el) => el.id),
@@ -310,7 +310,7 @@ export async function afterTemplate({ name, type, payload: data = {}, user = {},
310
310
  json: 1,
311
311
  })) ||
312
312
  {}; // add?
313
- const { rows: properties = [] } = await client.query(`select name, title, format, data from admin.custom_column
313
+ const { rows: properties = [] } = await client.query(`select name, title, format, data from admin.custom_column
314
314
  where entity=$1 and uid=$2`, [table || name, uid]);
315
315
  await Promise.all(properties.map(async (el) => {
316
316
  const clsData = el.data
@@ -347,13 +347,13 @@ export async function afterUpdate({ table, body = {}, payload: res = {}, user =
347
347
  return null;
348
348
  const pk = client?.pk?.[loadTable?.table || table];
349
349
  const id = res[pk];
350
- const { rows: properties = [] } = await client.query(`select column_id, name, title, format, data from admin.custom_column
350
+ const { rows: properties = [] } = await client.query(`select column_id, name, title, format, data from admin.custom_column
351
351
  where entity=$1 and uid=$2`, [table, uid]);
352
352
  if (!id || !properties?.length || !client.pk?.["crm.extra_data"])
353
353
  return null;
354
354
  const q = `delete from crm.extra_data where property_entity='${table}' and object_id='${id}';${properties
355
355
  .filter((el) => Object.keys(body).includes(el.name))
356
- .map((el) => `insert into crm.extra_data(property_id,property_key,property_entity,object_id,${el.format?.toLowerCase() === "date" ? "value_date" : "value_text"})
356
+ .map((el) => `insert into crm.extra_data(property_id,property_key,property_entity,object_id,${el.format?.toLowerCase() === "date" ? "value_date" : "value_text"})
357
357
  select '${el.column_id}', '${el.name}', '${table}', '${id}', ${el.format?.toLowerCase() === "date"
358
358
  ? `'${body[el.name]}'::timestamp without time zone`
359
359
  : `'${body[el.name]}'::text`}`)
@@ -375,13 +375,13 @@ export async function afterInsert({ table, body, payload: res = {}, user = {}, }
375
375
  return null;
376
376
  const pk = client?.pk?.[loadTable?.table || table];
377
377
  const id = res.rows?.[0]?.[pk];
378
- const { rows: properties = [] } = await client.query(`select column_id, name, title, format, data from admin.custom_column
378
+ const { rows: properties = [] } = await client.query(`select column_id, name, title, format, data from admin.custom_column
379
379
  where entity=$1 and uid=$2`, [table, uid]);
380
380
  if (!id || !properties?.length)
381
381
  return null;
382
382
  const q = properties
383
383
  .filter((el) => Object.keys(body).includes(el.name))
384
- .map((el) => `insert into crm.extra_data(property_id,property_key,property_entity,object_id,${el.format?.toLowerCase() === "date" ? "value_date" : "value_text"})
384
+ .map((el) => `insert into crm.extra_data(property_id,property_key,property_entity,object_id,${el.format?.toLowerCase() === "date" ? "value_date" : "value_text"})
385
385
  select '${el.column_id}', '${el.name}', '${table}', '${id}', ${el.format?.toLowerCase() === "date"
386
386
  ? `'${body[el.name]}'::timestamp without time zone`
387
387
  : `'${body[el.name]}'::text`}`)
@@ -1,10 +1,10 @@
1
- [
2
- {
3
- "id": "a",
4
- "text": "NO ACTION"
5
- },
6
- {
7
- "id": "c",
8
- "text": "CASCADE"
9
- }
1
+ [
2
+ {
3
+ "id": "a",
4
+ "text": "NO ACTION"
5
+ },
6
+ {
7
+ "id": "c",
8
+ "text": "CASCADE"
9
+ }
10
10
  ]
@@ -1,6 +1,6 @@
1
- [
2
- {
3
- "id": "s",
4
- "text": "SIMPLE"
5
- }
1
+ [
2
+ {
3
+ "id": "s",
4
+ "text": "SIMPLE"
5
+ }
6
6
  ]
@@ -1,18 +1,18 @@
1
- [
2
- {
3
- "id": "u",
4
- "text": "UNIQUE"
5
- },
6
- {
7
- "id": "p",
8
- "text": "PRIMARY KEY"
9
- },
10
- {
11
- "id": "f",
12
- "text": "FOREIGN KEY"
13
- },
14
- {
15
- "id": "c",
16
- "text": "CHECK"
17
- }
1
+ [
2
+ {
3
+ "id": "u",
4
+ "text": "UNIQUE"
5
+ },
6
+ {
7
+ "id": "p",
8
+ "text": "PRIMARY KEY"
9
+ },
10
+ {
11
+ "id": "f",
12
+ "text": "FOREIGN KEY"
13
+ },
14
+ {
15
+ "id": "c",
16
+ "text": "CHECK"
17
+ }
18
18
  ]
@@ -1,14 +1,14 @@
1
- [
2
- {
3
- "id": "regular",
4
- "text": "Regular"
5
- },
6
- {
7
- "id": "viewer",
8
- "text": "Viewer"
9
- },
10
- {
11
- "id": "admin",
12
- "text": "Admin"
13
- }
1
+ [
2
+ {
3
+ "id": "regular",
4
+ "text": "Regular"
5
+ },
6
+ {
7
+ "id": "viewer",
8
+ "text": "Viewer"
9
+ },
10
+ {
11
+ "id": "admin",
12
+ "text": "Admin"
13
+ }
14
14
  ]
@@ -1,18 +1,18 @@
1
- -- schema: {{nspname}}
2
-
3
- CREATE schema if not exists {{nspname}};
4
-
5
- {{#each rows}}
6
- -- {{{description}}}
7
-
8
- CREATE TABLE if not exists {{nspname}}.{{relname}}
9
- (
10
- {{#each columns}}
11
- {{column_name}} {{data_type}} {{#unless is_nullable}}NOT NULL{{/unless}}{{#if column_default}}DEFAULT {{column_default}}{{/if}}{{#ifCond @index '!=' (_math ../columns.length '-' 1)}},{{/ifCond}} -- {{{coalesce description '-'}}}
12
- {{/each}}{{#if constraints.length}},{{/if}}
13
- {{#each constraints}}
14
- CONSTRAINT {{constraint_name}} {{#ifCond constraint_type '==' 'c'}} {{check_definition}} {{/ifCond}} {{#ifCond constraint_type '==' 'f'}}FOREIGN KEY ({{foreign_column}}) REFERENCES {{foreign_table}} ({{foreign_column}}) MATCH {{select confmatchtype data="constraint_matchtype"}} ON UPDATE {{select confupdtype data="constraint_action"}} ON DELETE {{select confdeltype data="constraint_action"}}{{^}}{{#ifCond constraint_type '!=' 'c'}}{{select constraint_type data="constraint_type_full"}} ({{column_name}}){{/ifCond}}{{/ifCond}}{{#ifCond @index '!=' (_math ../constraints.length '-' 1)}},{{/ifCond}}
15
- {{/each}}
16
- );
17
-
1
+ -- schema: {{nspname}}
2
+
3
+ CREATE schema if not exists {{nspname}};
4
+
5
+ {{#each rows}}
6
+ -- {{{description}}}
7
+
8
+ CREATE TABLE if not exists {{nspname}}.{{relname}}
9
+ (
10
+ {{#each columns}}
11
+ {{column_name}} {{data_type}} {{#unless is_nullable}}NOT NULL{{/unless}}{{#if column_default}}DEFAULT {{column_default}}{{/if}}{{#ifCond @index '!=' (_math ../columns.length '-' 1)}},{{/ifCond}} -- {{{coalesce description '-'}}}
12
+ {{/each}}{{#if constraints.length}},{{/if}}
13
+ {{#each constraints}}
14
+ CONSTRAINT {{constraint_name}} {{#ifCond constraint_type '==' 'c'}} {{check_definition}} {{/ifCond}} {{#ifCond constraint_type '==' 'f'}}FOREIGN KEY ({{foreign_column}}) REFERENCES {{foreign_table}} ({{foreign_column}}) MATCH {{select confmatchtype data="constraint_matchtype"}} ON UPDATE {{select confupdtype data="constraint_action"}} ON DELETE {{select confdeltype data="constraint_action"}}{{^}}{{#ifCond constraint_type '!=' 'c'}}{{select constraint_type data="constraint_type_full"}} ({{column_name}}){{/ifCond}}{{/ifCond}}{{#ifCond @index '!=' (_math ../constraints.length '-' 1)}},{{/ifCond}}
15
+ {{/each}}
16
+ );
17
+
18
18
  {{/each}}
@@ -1,15 +1,15 @@
1
- #!/bin/bash
2
- rootDir=`echo $(dirname "$0")`
3
- echo "$rootDir/passwd"
4
-
5
- if [ -e "$rootDir/../passwd" ]
6
- then
7
- password=`echo -n "$2" | sha1sum | awk '{print $1}'`
8
- echo "$1:$password"
9
- echo "$1:$password" >> "$rootDir/../passwd"
10
- else
11
- > passwd
12
- password=`echo -n "$2" | sha1sum | awk '{print $1}'`
13
- echo "$1:$password"
14
- echo "$1:$password" > "$rootDir/../passwd"
1
+ #!/bin/bash
2
+ rootDir=`echo $(dirname "$0")`
3
+ echo "$rootDir/passwd"
4
+
5
+ if [ -e "$rootDir/../passwd" ]
6
+ then
7
+ password=`echo -n "$2" | sha1sum | awk '{print $1}'`
8
+ echo "$1:$password"
9
+ echo "$1:$password" >> "$rootDir/../passwd"
10
+ else
11
+ > passwd
12
+ password=`echo -n "$2" | sha1sum | awk '{print $1}'`
13
+ echo "$1:$password"
14
+ echo "$1:$password" > "$rootDir/../passwd"
15
15
  fi
@@ -79,57 +79,57 @@ async function saveFile(data, filename) {
79
79
  async function schemaItem({ pg, table, schema, debug, }) {
80
80
  if (!schema && !table)
81
81
  return new Error("param schema is required");
82
- const { rows: schemaInfo } = await pg.query(`select c.oid,relname,nspname,obj_description(c.oid) as description,
83
- (
84
- select json_agg(row_to_json(q))
85
- from (
86
- select
87
- column_name,
88
- case
89
- when data_type='USER-DEFINED' AND udt_name='geometry' THEN 'geometry'
90
- when data_type='ARRAY' AND udt_name='_text' THEN 'text[]'
91
- when data_type='ARRAY' AND udt_name='_int4' THEN 'integer[]'
92
- else data_type
93
- end as data_type,
94
- ordinal_position,
95
- column_default,
96
- is_nullable,
97
- case
98
- when column_name='uid' then 'ідентифікатор автора запису в БД'
99
- when column_name='cdate' then 'Дата створення запису в БД'
100
- when column_name='editor_id' then 'Ідентифікатор автора, який останій вніс зміни в запис'
101
- when column_name='editor_date' then 'Час останії зміни в записі'
102
- when column_name='files' then 'Системна колонка'
103
- when column_name='doc_status' then 'Статус документа'
104
- when column_name='reg_status' then 'Статус реєстрації'
105
- when column_name='obj_version' then 'Версія запису'
106
- else col_description(a.attrelid,ordinal_position)
107
- end as description
108
- from information_schema.columns col
109
- LEFT JOIN pg_attribute a ON col.column_name=a.attname and c.oid = a.attrelid
110
- where col.table_schema=nspname and col.table_name=relname
111
- )q
112
- ) as columns
113
- from pg_class c
114
- LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
115
- where ${table ? `nspname||'.'||relname='${table}'` : `'${schema}'=nspname`} and relam=2
82
+ const { rows: schemaInfo } = await pg.query(`select c.oid,relname,nspname,obj_description(c.oid) as description,
83
+ (
84
+ select json_agg(row_to_json(q))
85
+ from (
86
+ select
87
+ column_name,
88
+ case
89
+ when data_type='USER-DEFINED' AND udt_name='geometry' THEN 'geometry'
90
+ when data_type='ARRAY' AND udt_name='_text' THEN 'text[]'
91
+ when data_type='ARRAY' AND udt_name='_int4' THEN 'integer[]'
92
+ else data_type
93
+ end as data_type,
94
+ ordinal_position,
95
+ column_default,
96
+ is_nullable,
97
+ case
98
+ when column_name='uid' then 'ідентифікатор автора запису в БД'
99
+ when column_name='cdate' then 'Дата створення запису в БД'
100
+ when column_name='editor_id' then 'Ідентифікатор автора, який останій вніс зміни в запис'
101
+ when column_name='editor_date' then 'Час останії зміни в записі'
102
+ when column_name='files' then 'Системна колонка'
103
+ when column_name='doc_status' then 'Статус документа'
104
+ when column_name='reg_status' then 'Статус реєстрації'
105
+ when column_name='obj_version' then 'Версія запису'
106
+ else col_description(a.attrelid,ordinal_position)
107
+ end as description
108
+ from information_schema.columns col
109
+ LEFT JOIN pg_attribute a ON col.column_name=a.attname and c.oid = a.attrelid
110
+ where col.table_schema=nspname and col.table_name=relname
111
+ )q
112
+ ) as columns
113
+ from pg_class c
114
+ LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
115
+ where ${table ? `nspname||'.'||relname='${table}'` : `'${schema}'=nspname`} and relam=2
116
116
  order by nspname,relname`);
117
117
  if (!schemaInfo?.length)
118
118
  throw new Error("invalid params");
119
- const { rows: constraints } = await pg.query(`select con.conrelid::regclass as constraint_table, a.column_name,
120
- con.conname as constraint_name,contype as constraint_type, con.confrelid::regclass as foreign_table,
121
- con.confupdtype, con.confdeltype, con.confmatchtype, u.column_name as foreign_column,
122
- case when contype='c' then pg_get_constraintdef(con.oid, true) else null end AS check_definition from pg_constraint con
123
- left join pg_class c ON c.oid = con.conrelid
124
- left join pg_namespace n ON n.oid = c.relnamespace
125
- left join lateral (
126
- select string_agg(a.attname,',') as column_name from pg_attribute a
127
- where con.conrelid = a.attrelid and a.attnum = any(con.conkey) limit 1
128
- )a on 1=1
129
- left join lateral (
130
- select column_name from information_schema.constraint_column_usage u
131
- where conname=u.constraint_name limit 1
132
- )u on 1=1
119
+ const { rows: constraints } = await pg.query(`select con.conrelid::regclass as constraint_table, a.column_name,
120
+ con.conname as constraint_name,contype as constraint_type, con.confrelid::regclass as foreign_table,
121
+ con.confupdtype, con.confdeltype, con.confmatchtype, u.column_name as foreign_column,
122
+ case when contype='c' then pg_get_constraintdef(con.oid, true) else null end AS check_definition from pg_constraint con
123
+ left join pg_class c ON c.oid = con.conrelid
124
+ left join pg_namespace n ON n.oid = c.relnamespace
125
+ left join lateral (
126
+ select string_agg(a.attname,',') as column_name from pg_attribute a
127
+ where con.conrelid = a.attrelid and a.attnum = any(con.conkey) limit 1
128
+ )a on 1=1
129
+ left join lateral (
130
+ select column_name from information_schema.constraint_column_usage u
131
+ where conname=u.constraint_name limit 1
132
+ )u on 1=1
133
133
  where ${table ? `conrelid::regclass::text = '${table}'` : `nspname = '${schema}'`}`);
134
134
  // add table constraints, mermaid
135
135
  schemaInfo?.forEach((row) => {