@opengis/fastify-table 1.3.15 → 1.3.16

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "1.3.15",
3
+ "version": "1.3.16",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [
@@ -1,7 +1,10 @@
1
1
  import path from 'node:path';
2
+ import { createHash } from 'node:crypto';
2
3
  import { existsSync, readFileSync } from 'node:fs';
3
4
 
4
- import { logger, pgClients } from '../../../utils.js';
5
+ import { config, logger, pgClients, getRedis } from '../../../utils.js';
6
+
7
+ const rclient = getRedis();
5
8
 
6
9
  export default async function execSql(filepath, pg = pgClients.client) {
7
10
  const start = Date.now();
@@ -21,9 +24,18 @@ export default async function execSql(filepath, pg = pgClients.client) {
21
24
 
22
25
  const sql = readFileSync(filepath, 'utf-8');
23
26
 
27
+ const hash = createHash('md5').update(sql).digest('hex');
28
+ const hashes = await rclient.hgetall(`${pg.options?.database}:migration-hashes`).then(obj => Object.keys(obj));
29
+
30
+ if (hashes.includes(hash) && !config.disableCache) {
31
+ console.log(filename, 'skip equal hash', Date.now() - start);
32
+ return null;
33
+ }
34
+
24
35
  try {
25
36
  console.log(filename, 'start', Date.now() - start);
26
37
  await pg.query(sql);
38
+ if (!config.disableCache) await rclient.hset(`${pg.options?.database}:migration-hashes`, hash, 1);
27
39
  console.log(filename, 'finish', Date.now() - start);
28
40
  logger.file('migration/success', {
29
41
  filepath,