@catladder/cli 4.2.2 → 4.4.0

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
@@ -53,7 +53,7 @@
53
53
  }
54
54
  ],
55
55
  "license": "MIT",
56
- "version": "4.2.2",
56
+ "version": "4.4.0",
57
57
  "scripts": {
58
58
  "lint": "eslint \"src/**/*.ts\"",
59
59
  "lint:fix": "eslint \"src/**/*.ts\" --fix",
@@ -37,24 +37,26 @@ const createCopyDbScript = ({
37
37
  const copyDBScript = `
38
38
  set -e
39
39
 
40
-
41
-
42
- dumptmp=$(mktemp /tmp/dump.XXXXXX)
43
-
44
- echo "Dumping file to $dumptmp"
45
- pg_dump --dbname=postgres://${encodedSourceUsername}:${encodedSourcePassword}@localhost:${sourcePort}/${sourceDbName} --no-owner --no-privileges > $dumptmp
46
- echo "dump done"
47
40
  ${targetPSQL(
48
41
  `-c 'drop database "${targetDbName}" WITH (FORCE)' 1> /dev/null || true`,
49
42
  )}
50
43
  ${targetPSQL(`-c 'create database "${targetDbName}"' 1> /dev/null`)}
51
- echo "Restoring dump..."
52
- ${targetPSQL(`"${targetDbName}" < $dumptmp 1> /dev/null`)}
53
-
44
+ echo "Estimating database size..."
45
+ DB_SIZE=$(PGPASSWORD=${encodedSourcePassword} psql --dbname=postgres://${encodedSourceUsername}:${encodedSourcePassword}@localhost:${sourcePort}/${sourceDbName} -t -A -c "SELECT pg_database_size('${sourceDbName}')")
46
+ # pg_database_size includes indexes, TOAST, and free space — pg_dump output is roughly 40% of that
47
+ ESTIMATED_DUMP_SIZE=$((DB_SIZE * 40 / 100))
48
+ echo "Estimated dump size: $((ESTIMATED_DUMP_SIZE / 1024 / 1024)) MB (~40% of $((DB_SIZE / 1024 / 1024)) MB database size)"
49
+
50
+ PROGRESS=""
51
+ if command -v pv &> /dev/null; then
52
+ PROGRESS="pv -s $ESTIMATED_DUMP_SIZE |"
53
+ else
54
+ echo "(install 'pv' for progress info)"
55
+ fi
56
+
57
+ echo "Dumping and restoring via pipe..."
58
+ eval "pg_dump --dbname=postgres://${encodedSourceUsername}:${encodedSourcePassword}@localhost:${sourcePort}/${sourceDbName} --no-owner --no-privileges | $PROGRESS ${targetPSQL(`"${targetDbName}" 1> /dev/null`)}"
54
59
 
55
- echo "Clean up..."
56
- set +e
57
- rm $dumptmp
58
60
  echo "\n🐱 Done!"
59
61
  `;
60
62
  return copyDBScript;