Skip to content

Commit

Permalink
Merge pull request #43 from map3xyz/db-utils
Browse files Browse the repository at this point in the history
Adding safety check to assets DB process
  • Loading branch information
pellicceama authored Mar 13, 2023
2 parents 7293619 + 814d9e5 commit d9fe734
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@map3xyz/assets-helper",
"version": "1.0.189",
"version": "1.0.191",
"description": "A library for maintaining the assets repo.",
"author": "pellicceama",
"keywords": [
Expand All @@ -23,7 +23,7 @@
"prepareTest": "yarn ts-node ./src/cache.ts",
"test": "yarn prepareTest && yarn build && ava",
"bundle": "yarn build && pkg . --out-dir ./exec/",
"release-db": "ts-node ./src/releaser/sync/sync-database.ts"
"release-db": "ts-node ./src/releaser/db/sync-database.ts"
},
"devDependencies": {
"@types/ethereum-checksum-address": "^0.0.0",
Expand Down
14 changes: 14 additions & 0 deletions src/releaser/db/sync-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,27 @@ export async function createAssetDb(assetRepo: string = "/tmp/assets", assetDb:

await db.exec("COMMIT");

const assetsNumber = await getNumberOfAssetsInDb(db);

if(assetsNumber < (process.env.MIN_NUMBER_OF_ASSETS || 1000)) {
console.error(`Asset DB has only ${assetsNumber} assets, exiting`);
process.exit(1);
}

console.log(`Added ${assetsNumber} to Assets DB`);

await db.close();

await createRelease(octokit, commitId, assetDb);

console.log("Asset DB Released");
return Promise.resolve();
}

async function getNumberOfAssetsInDb(db): Promise<number> {
const result = await db.get("SELECT COUNT(*) AS count FROM asset");
return result.count;
}
async function getLatestRelease(octokit: Octokit): Promise<string | null> {
let release = null;

Expand Down

0 comments on commit d9fe734

Please sign in to comment.