Skip to content

Commit

Permalink
Merge pull request #40 from bcgov/remove-filepath-migration
Browse files Browse the repository at this point in the history
Remove running of the filepath migration
  • Loading branch information
timwekkenbc authored Oct 8, 2024
2 parents ae4ee11 + f08c6c3 commit 3aee615
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src/api/ruleData/ruleData.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export class RuleData {

@Prop({ description: 'If the rule has been published' })
isPublished?: boolean;

// TODO: REMOVE AFTER MIGRATIONS ALL COMPLETE
@Prop({ description: 'This is being deprecated' })
goRulesJSONFilename?: string;
}

export type RuleDataDocument = RuleData & Document;
Expand Down
6 changes: 0 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { NestFactory } from '@nestjs/core';
import { NestExpressApplication } from '@nestjs/platform-express';
import { AppModule } from './app.module';
// TODO: Remove this once it has run on prod
import filepathMigration from './migrations/filepath-migration';

async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule);
app.enableCors({
origin: process.env.FRONTEND_URI,
});
const port = process.env.PORT || 3000;
// TODO: Remove this call once it has run on prod
if (process.env.NODE_ENV !== 'test') {
filepathMigration();
}
await app.listen(process.env.PORT || 3000);
console.log(`Server is running on port ${port} with ${process.env.FRONTEND_URI} allowed origins.`);
}
Expand Down
14 changes: 11 additions & 3 deletions src/migrations/filepath-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@
*/

import { connect, connection, model } from 'mongoose';
import { RuleDataDocument, RuleDataSchema } from '../api/ruleData/ruleData.schema';
import { Prop, SchemaFactory } from '@nestjs/mongoose';
import { RuleData } from '../api/ruleData/ruleData.schema';
import { deriveNameFromFilepath } from '../utils/helpers';

const RuleData = model<RuleDataDocument>('RuleData', RuleDataSchema);
class OldRuleData extends RuleData {
@Prop({ description: 'This has now been deprecated' })
goRulesJSONFilename?: string;
}

export const RuleDataSchema = SchemaFactory.createForClass(OldRuleData);

const oldRuleData = model('RuleData', RuleDataSchema);

export default async function filepathMigration() {
await connect(process.env.MONGODB_URL);

try {
const documents = await RuleData.find();
const documents = await oldRuleData.find();

for (const doc of documents) {
if (!doc.filepath) {
Expand Down

0 comments on commit 3aee615

Please sign in to comment.