Store reusable scraper capabilities in scrape DB
This commit is contained in:
@@ -57,7 +57,11 @@ const connection = await mariadb.createConnection({
|
||||
try {
|
||||
await connection.query(`CREATE DATABASE IF NOT EXISTS \`${scrapeDb}\` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci`);
|
||||
const schemaSql = await fs.readFile("sql/local-scrape-db.sql", "utf8");
|
||||
for (const statement of schemaSql.split(/;\s*(?:\r?\n|$)/).map((item) => item.trim()).filter(Boolean)) {
|
||||
const schemaStatements = schemaSql
|
||||
.split(/;\s*(?:\r?\n|$)/)
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean);
|
||||
for (const statement of schemaStatements) {
|
||||
await connection.query(statement);
|
||||
}
|
||||
|
||||
@@ -250,9 +254,17 @@ try {
|
||||
priority = VALUES(priority)
|
||||
`);
|
||||
|
||||
for (const statement of schemaStatements.filter(isCapabilitySeedStatement)) {
|
||||
await connection.query(statement);
|
||||
}
|
||||
|
||||
const sources = await queryRows(connection, `SELECT COUNT(*) AS total FROM \`${scrapeDb}\`.scrape_sources`);
|
||||
const mappings = await queryRows(connection, `SELECT COUNT(*) AS total FROM \`${scrapeDb}\`.scrape_manufacturer_sources`);
|
||||
console.log(`Scrape mapping migration ready: ${sources[0]?.total || 0} sources, ${mappings[0]?.total || 0} manufacturer mappings.`);
|
||||
} finally {
|
||||
await connection.end();
|
||||
}
|
||||
|
||||
function isCapabilitySeedStatement(statement) {
|
||||
return /^INSERT INTO `scrape_(source_capabilities|manufacturer_source_capabilities)`/i.test(statement);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user