@opengis/admin 0.3.40 → 0.3.42

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.
@@ -1,4 +1,4 @@
1
- import { _ as n, f as m } from "./import-file-D7kmC9pj.js";
1
+ import { _ as n, f as m } from "./import-file-KkQTE8rh.js";
2
2
  import { u as p } from "./user-B_2kh6ic.js";
3
3
  import { resolveComponent as f, openBlock as u, createElementBlock as d, createElementVNode as o, createBlock as h, createCommentVNode as b } from "vue";
4
4
  const x = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.3.40",
3
+ "version": "0.3.42",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -48,8 +48,8 @@
48
48
  "@fullcalendar/vue3": "^6.1.15",
49
49
  "@opengis/fastify-auth": "^1.0.73",
50
50
  "@opengis/fastify-file": "^1.0.42",
51
- "@opengis/fastify-table": "^1.2.88",
52
- "@opengis/v3-core": "^0.3.93",
51
+ "@opengis/fastify-table": "^1.2.96",
52
+ "@opengis/v3-core": "^0.3.112",
53
53
  "@opengis/v3-filter": "^0.0.72",
54
54
  "@tiptap/core": "^2.8.0",
55
55
  "@tiptap/extension-color": "^2.8.0",
@@ -95,4 +95,4 @@
95
95
  "vitepress-plugin-tabs": "^0.5.0",
96
96
  "vitepress-sidebar": "1.30.2"
97
97
  }
98
- }
98
+ }
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { createHash } from 'node:crypto';
3
- import { readFileSync } from 'node:fs';
3
+ import { readFileSync, writeFileSync } from 'node:fs';
4
4
 
5
5
  import {
6
6
  getTemplatePath, addHook, getToken, getTemplate, config, pgClients, initPG, getRedis, logger,
@@ -12,6 +12,9 @@ import printTemplates from '../routes/print/controllers/printTemplates.js';
12
12
  const { client } = pgClients;
13
13
 
14
14
  const rclient = getRedis();
15
+ const cwd = process.cwd();
16
+
17
+ const logDir = path.join(cwd, 'log/migration');
15
18
 
16
19
  export default async function plugin(fastify) {
17
20
  const user1 = config?.auth?.disable || process.env.NODE_ENV !== 'admin' ? { uid: '1' } : null;
@@ -116,33 +119,44 @@ export default async function plugin(fastify) {
116
119
  ?.map((el) => ({ name: el[0], module: path.basename(path.dirname(path.dirname(el[1]))), type: { 'json': 'cls', 'sql': 'select' }[el[2]] }))
117
120
  if (!cls?.length) return;
118
121
 
119
- const dupes = cls.filter((el, idx, arr) => arr.map((item) => item.name).indexOf(el.name) !== idx);
120
- //console.log('cls insert skip dupes', dupes.map((el) => el.name));
121
-
122
122
  try {
123
123
  const hashes = await rclient.hgetall('cls-insert-hashes').then(obj => Object.keys(obj));
124
- const names = await pgClients.client.query(`select array_agg(name) from admin.cls where parent is null`).then(el => el.rows?.[0]?.array_agg || []);
124
+ const dbdata = await client.query(`select json_object_agg(name, hash) from admin.cls where parent is null`).then(el => el.rows?.[0]?.json_object_agg || {});
125
+ const names = Object.keys(dbdata);
125
126
  const qHashes = await Promise.all(cls.filter((el, idx, arr) => arr.map((item) => item.name).indexOf(el.name) === idx).map(async (el) => {
126
127
  const { name, module, type } = el;
127
128
  const loadTemplate = await getTemplate(type, name);
128
- const hash = createHash('md5').update(type === 'cls' ? JSON.stringify(loadTemplate) : (loadTemplate?.sql || loadTemplate)).digest('hex');
129
- if (type === 'select' && (!hashes.includes(hash) || !names.includes(name))) {
130
- clsQuery.push(`insert into admin.cls(name,type,data,module) values('${name}','sql','${(loadTemplate?.sql || loadTemplate)?.replace(/'/g, "''")}', '${module?.replace(/'/g, "''")}')`);
131
- return hash;
132
- } else if (type === 'cls' && loadTemplate?.length && (!hashes.includes(hash) || !names.includes(name))) {
133
- clsQuery.push(`insert into admin.cls(name,type, module) values('${name}','json', '${module?.replace(/'/g, "''")}');
129
+ el.hash = createHash('md5').update(type === 'cls' ? JSON.stringify(loadTemplate) : (loadTemplate?.sql || loadTemplate)).digest('hex');
130
+ el.dbhash = dbdata[name];
131
+
132
+ // check for changes by redis hash / dropped from db / changed at git project
133
+ el.update = !hashes.includes(el.hash) || !names.includes(name) || el.hash !== el.dbhash;
134
+
135
+ if (type === 'select' && (loadTemplate?.sql || loadTemplate) && el.update) {
136
+ clsQuery.push(`insert into admin.cls(name,type,data,module,hash) values('${name}','sql','${(loadTemplate?.sql || loadTemplate)?.replace(/'/g, "''")}', '${module?.replace(/'/g, "''")}','${el.hash}')`);
137
+ console.log(name, type, 'insert fresh select');
138
+ return el.hash;
139
+ } else if (type === 'cls' && loadTemplate?.length && el.update) {
140
+ clsQuery.push(`insert into admin.cls(name,type, module,hash) values('${name}','json', '${module?.replace(/'/g, "''")}','${el.hash}');
134
141
  insert into admin.cls(code,name,parent,icon,data)
135
142
  select value->>'id',value->>'text','${name}',value->>'icon',value->>'data'
136
143
  from json_array_elements('${JSON.stringify(loadTemplate).replace(/'/g, "''")}'::json)`);
137
- return hash;
138
- } else if (hashes.includes(hash)) {
144
+ console.log(name, type, 'insert fresh cls');
145
+ return el.hash;
146
+ } else if (hashes.includes(el.hash)) {
139
147
  console.log(name, type, names.includes(name) ? 'skip equal hash' : 'insert missing cls');
148
+ return el.hash;
140
149
  } else {
141
150
  console.log(name, type, 'empty');
151
+ return el.hash;
142
152
  }
143
153
  }));
144
154
 
145
- const { rowCount = 0 } = await client.query('delete from admin.cls where $1::text[] && array[name,parent]', [cls.map(el => el.name)]);
155
+ // debug
156
+ writeFileSync(path.join(logDir, `${path.basename(cwd)}-${client.options?.database}-cls.sql`), clsQuery.filter((el) => el).join(';'));
157
+ writeFileSync(path.join(logDir, `${path.basename(cwd)}-${client.options?.database}-cls.json`), JSON.stringify(cls));
158
+
159
+ const { rowCount = 0 } = await client.query('delete from admin.cls where $1::text[] && array[name,parent]', [cls.filter(el => el.update).map(el => el.name)]);
146
160
  console.log('admin/hook old cls deleted', rowCount);
147
161
  if (clsQuery.filter((el) => el).length) {
148
162
  console.log('admin/hook cls sql start', clsQuery?.length);