Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(all): Add updated_at to all entities #763

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions scripts/dbRefresh.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readdirSync, unlinkSync, writeFileSync } from 'fs';
import { readdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs';

import { execSync } from 'child_process';

Expand Down Expand Up @@ -63,13 +63,30 @@ const uploadTablesFromFolder = (jsonDbDir: string, collectionPrefix = '') => {
// --jsonArray
// --drop
console.log(`importing ${dataName}...`);

// Read the JSON file
const data = JSON.parse(readFileSync(filepath, 'utf8'));

// Add updated_at field to each record
const updatedData = data.map((record: any) => ({
...record,
updated_at: new Date().toISOString(),
}));

// Write the modified data to a temporary file
const tempFilepath = `${jsonDbDir}/temp-${filename}`;
writeFileSync(tempFilepath, JSON.stringify(updatedData, null, 2), 'utf8');

const exec_string =
`mongoimport --uri ${mongodbUri}` +
` --collection ${collectionName}` +
` --file ${filepath}` +
` --file ${tempFilepath}` +
' --jsonArray' +
' --drop';
execSync(exec_string);

// Remove the temporary file
unlinkSync(tempFilepath);
});

// Make collections table
Expand Down
Loading