Skip to content

Commit 8cbab56

Browse files
committed
add collection scaling logic to backupCollection, add .gitkeep files to preserve directories
1 parent 01ce089 commit 8cbab56

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

.dss/data/backups/.gitkeep

Whitespace-only changes.

.dss/data/json/.gitkeep

Whitespace-only changes.

lib/index.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,28 @@ const Database = dataURI => {
1515
let getCollection, updateCollection, backupCollection, storeMedia;
1616

1717
backupCollection = async collectionName => {
18-
const data = await fs.readFile(`${dataURI}/${collectionName}.json`, 'utf8');
18+
const files = await fs.readdir(dataURI);
19+
20+
const documents = files
21+
.filter(file => (
22+
file
23+
.split('.')[0]
24+
.split('-')[0] === collectionName
25+
))
26+
.map(file => (
27+
file.replace('.json', '')
28+
));
29+
30+
const fileName = documents.length > 1
31+
? documents.sort().pop()
32+
: collectionName;
33+
34+
const fileSrc = `${dataURI}/${fileName}.json`;
35+
36+
const data = await fs.readFile(fileSrc, 'utf8');
1937

2038
await fs.writeFile(
21-
`${dataURI}/${collectionName}-${Date.now()}.json`,
39+
`${dataURI}/backups/${collectionName}-${Date.now()}.json`,
2240
data,
2341
'utf8'
2442
);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diamond-search-and-store",
3-
"version": "0.2.7",
3+
"version": "0.2.9",
44
"engines": {
55
"node": "16.14.2"
66
},

0 commit comments

Comments
 (0)