Skip to content

Commit e99ed09

Browse files
authored
feat(all): Add updated_at to all entities (#763)
1 parent 38cf8e9 commit e99ed09

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

scripts/dbRefresh.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readdirSync, unlinkSync, writeFileSync } from 'fs';
1+
import { readdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs';
22

33
import { execSync } from 'child_process';
44

@@ -63,13 +63,30 @@ const uploadTablesFromFolder = (jsonDbDir: string, collectionPrefix = '') => {
6363
// --jsonArray
6464
// --drop
6565
console.log(`importing ${dataName}...`);
66+
67+
// Read the JSON file
68+
const data = JSON.parse(readFileSync(filepath, 'utf8'));
69+
70+
// Add updated_at field to each record
71+
const updatedData = data.map((record: any) => ({
72+
...record,
73+
updated_at: new Date().toISOString(),
74+
}));
75+
76+
// Write the modified data to a temporary file
77+
const tempFilepath = `${jsonDbDir}/temp-${filename}`;
78+
writeFileSync(tempFilepath, JSON.stringify(updatedData, null, 2), 'utf8');
79+
6680
const exec_string =
6781
`mongoimport --uri ${mongodbUri}` +
6882
` --collection ${collectionName}` +
69-
` --file ${filepath}` +
83+
` --file ${tempFilepath}` +
7084
' --jsonArray' +
7185
' --drop';
7286
execSync(exec_string);
87+
88+
// Remove the temporary file
89+
unlinkSync(tempFilepath);
7390
});
7491

7592
// Make collections table

0 commit comments

Comments
 (0)