Skip to content

Commit

Permalink
fix: migration
Browse files Browse the repository at this point in the history
  • Loading branch information
TitoMoi committed Sep 27, 2023
1 parent acf248b commit e55ba8f
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/app/migration/service/migration.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
writeJsonSync,
} from "fs-extra";
import { MigrationInterface } from "app/migration/model/migration.model";
import { AssignTypeService } from "app/assigntype/service/assigntype.service";
import { RoomService } from "app/room/service/room.service";
import path from "path";
import { gzip } from "pako";

Expand All @@ -18,23 +16,11 @@ import { gzip } from "pako";
})
export class MigrationService {
//Migrate data based on the model
constructor(
private configService: ConfigService,
private assignTypeService: AssignTypeService,
private roomService: RoomService
) {}
constructor(private configService: ConfigService) {}

migrateData() {
//First migration
this.toV5();
this.saveData();
return;
}

saveData() {
//save them sync or the migration process breaks
this.assignTypeService.saveAssignTypesToFile(true);
this.roomService.saveRoomsToFile(true);
}

/*Based on git changes to the models **/
Expand All @@ -45,7 +31,7 @@ export class MigrationService {
this.configService.sourceFilesPath,
"assignment.json"
);
const assignments = readJsonSync(assignmentJsonPath);
const assignments = readJsonSync(assignmentJsonPath, { throws: false });
if (assignments) {
const gziped = gzip(JSON.stringify(assignments), { to: "string" });
writeFileSync(this.configService.assignmentsPath, gziped);
Expand All @@ -56,8 +42,9 @@ export class MigrationService {

//:::Polygons, territories and territory groups are now gzip

//TERRITORIES
const territoryJsonPath = path.join(this.configService.sourceFilesPath, "territory.json");
const territories = readJsonSync(territoryJsonPath);
const territories = readJsonSync(territoryJsonPath, { throws: false });
if (territories) {
const gziped = gzip(JSON.stringify(territories), { to: "string" });
writeFileSync(this.configService.territoriesPath, gziped);
Expand All @@ -71,7 +58,7 @@ export class MigrationService {
this.configService.sourceFilesPath,
"territoryGroup.json"
);
const territoryGroups = readJsonSync(territoryGroupJsonPath);
const territoryGroups = readJsonSync(territoryGroupJsonPath, { throws: false });
if (territoryGroups) {
const gziped = gzip(JSON.stringify(territoryGroups), { to: "string" });
writeFileSync(this.configService.territoryGroupsPath, gziped);
Expand All @@ -82,7 +69,7 @@ export class MigrationService {

//POLYGONS
const polygonsJsonPath = path.join(this.configService.sourceFilesPath, "polygons.json");
const polygons = readJsonSync(polygonsJsonPath);
const polygons = readJsonSync(polygonsJsonPath, { throws: false });
if (polygons) {
const gziped = gzip(JSON.stringify(polygons), { to: "string" });
writeFileSync(this.configService.polygonsPath, gziped);
Expand Down

0 comments on commit e55ba8f

Please sign in to comment.