feat: add software_hashes table schema and reimport pipeline
- Add softwareHashes Drizzle model (download_id PK, md5, crc32, size_bytes, inner_path, updated_at) - Update import_mysql.sh to reimport from JSON snapshot after DB wipe - Add pnpm scripts: update:hashes, export:hashes - Create data/zxdb/ directory for JSON snapshot storage claude-opus-4-6@MacFiver
This commit is contained in:
@@ -37,4 +37,49 @@ mysql $MYSQL_ARGS < ZXDB/ZXDB_mysql.sql
|
||||
# echo "CREATE ROLE IF NOT EXISTS 'zxdb_readonly';"
|
||||
# echo "GRANT SELECT, SHOW VIEW ON \`zxdb\`.* TO 'zxdb_readonly';"
|
||||
} | mysql --force $MYSQL_ARGS "$DB_NAME"
|
||||
# ---- Reimport software_hashes from JSON snapshot if available ----
|
||||
HASHES_SNAPSHOT="$SCRIPT_DIR/../data/zxdb/software_hashes.json"
|
||||
if [ -f "$HASHES_SNAPSHOT" ]; then
|
||||
echo "Reimporting software_hashes from $HASHES_SNAPSHOT ..."
|
||||
node -e "
|
||||
const fs = require('fs');
|
||||
const mysql = require('mysql2/promise');
|
||||
(async () => {
|
||||
const snap = JSON.parse(fs.readFileSync('$HASHES_SNAPSHOT', 'utf8'));
|
||||
if (!snap.rows || snap.rows.length === 0) {
|
||||
console.log(' No rows in snapshot, skipping.');
|
||||
return;
|
||||
}
|
||||
const pool = mysql.createPool({ uri: '$ZXDB_URL', connectionLimit: 1 });
|
||||
await pool.query(\`
|
||||
CREATE TABLE IF NOT EXISTS software_hashes (
|
||||
download_id INT NOT NULL PRIMARY KEY,
|
||||
md5 VARCHAR(32) NOT NULL,
|
||||
crc32 VARCHAR(8) NOT NULL,
|
||||
size_bytes BIGINT NOT NULL,
|
||||
inner_path VARCHAR(500) NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
INDEX idx_sh_md5 (md5),
|
||||
INDEX idx_sh_crc32 (crc32)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
|
||||
\`);
|
||||
await pool.query('TRUNCATE TABLE software_hashes');
|
||||
// Batch insert in chunks of 500
|
||||
const chunk = 500;
|
||||
for (let i = 0; i < snap.rows.length; i += chunk) {
|
||||
const batch = snap.rows.slice(i, i + chunk);
|
||||
const values = batch.map(r => [r.download_id, r.md5, r.crc32, r.size_bytes, r.inner_path, r.updated_at]);
|
||||
await pool.query(
|
||||
'INSERT INTO software_hashes (download_id, md5, crc32, size_bytes, inner_path, updated_at) VALUES ?',
|
||||
[values]
|
||||
);
|
||||
}
|
||||
console.log(' Imported ' + snap.rows.length + ' rows into software_hashes.');
|
||||
await pool.end();
|
||||
})().catch(e => { console.error(' Error reimporting software_hashes:', e.message); process.exit(0); });
|
||||
"
|
||||
else
|
||||
echo "No software_hashes snapshot found at $HASHES_SNAPSHOT — skipping reimport."
|
||||
fi
|
||||
|
||||
mysqldump --no-data -uroot -p -h${DB_HOST} -P${DB_PORT} "$DB_NAME" > ZXDB/ZXDB_mysql_STRUCTURE_ONLY.sql
|
||||
|
||||
Reference in New Issue
Block a user