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

DOP-4571: migration script for bad repo branches #1037

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
43 changes: 43 additions & 0 deletions modules/persistence/DOP-4571.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as dotenv from 'dotenv';
// dotenv.config() should be invoked immediately, before any other imports, to ensure config is present
dotenv.config();

import { pool, teardown } from './src/services/connector';

const migrate = async () => {
const db = await pool();
const collection = db.collection('repos_branches');
const repos = await collection.find().toArray();

for (let idx = 0; idx < repos.length; idx++) {
const problematicBranches: string[] = [];
const repo = repos[idx];
// if (repo.branches.length === 1) {
// continue;
// }
repo.branches.forEach((branch) => {
if (
!branch.publishOriginalBranchName &&
branch.urlSlug === branch.gitBranchName &&
!branch.urlAliases?.includes(branch.urlSlug)
) {
problematicBranches.push(branch.gitBranchName);
branch.publishOriginalBranchName = true;
}
});
if (problematicBranches.length) {
console.log(`updating repo with id ${repo._id} (${repo.repoName}) for branches ${problematicBranches}`);
await collection.updateOne({ _id: repo._id }, { $set: { branches: repo.branches } });
}
}

await teardown();
};

migrate()
.then(() => {
console.log('finished');
})
.catch((e) => {
console.error(e);
});
2 changes: 1 addition & 1 deletion modules/persistence/src/services/connector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ObjectId, Db, Document } from 'mongodb';
import { db as poolDb } from './pool';

// We should only ever have one client active at a time.
const atlasURL = `mongodb+srv://${process.env.MONGO_ATLAS_USERNAME}:${process.env.MONGO_ATLAS_PASSWORD}@${process.env.MONGO_ATLAS_HOST}/?retryWrites=true&w=majority&maxPoolSize=20`;
const atlasURL = `mongodb://${process.env.MONGO_ATLAS_HOST}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change was for local dev. not important :)

const client = new mongodb.MongoClient(atlasURL);

export const teardown = async () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/persistence/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"baseUrl": "./",
"types": ["adm-zip"]
},
"include": ["src/**/*.ts", "index.ts"],
"include": ["src/**/*.ts", "index.ts", "DOP-4571.ts"],
"exclude": ["node_modules", "tests/**/*.ts"]
}
Loading