removed migration code now that migration is complete

This commit is contained in:
2026-03-13 10:52:40 -05:00
parent 11daf918b6
commit bd8c610584
2 changed files with 8 additions and 118 deletions
+1 -100
View File
@@ -1095,104 +1095,6 @@ const runLegacyTagMigration = async () => {
}
};
const runLegacyJobIdTagMigration = async () => {
const currentUserId = pb.authStore.model?.id;
if (!currentUserId) return;
try {
const userRec = await pb.collection('users').getOne(currentUserId, { requestKey: null });
const prefs = userRec.Taskgrid_pref || {};
if (prefs.migratedLegacyJobIdTagsV1) return;
// Fetch all Notes (all users)
const notes = await pb.collection(NOTES_COLLECTION).getFullList({
requestKey: null
});
const extractLegacyJobNumbers = (tags: string[] | undefined) => {
if (!tags || tags.length === 0) return [];
const nums: string[] = [];
tags.forEach(t => {
if (!t.startsWith("job_id:")) return;
const val = t.split(":")[1]?.trim();
if (val && /^\d{4}$/.test(val)) nums.push(val);
});
return nums;
};
const legacyNumbers = new Set<string>();
notes.forEach(n => extractLegacyJobNumbers(n.tags).forEach(nm => legacyNumbers.add(nm)));
if (legacyNumbers.size > 0) {
const allNumbers = Array.from(legacyNumbers);
const jobMap = new Map<string, string>(); // jobNumber -> jobId
const chunkSize = 50;
for (let i = 0; i < allNumbers.length; i += chunkSize) {
const chunk = allNumbers.slice(i, i + chunkSize);
const filter = chunk.map(n => `Job_Number = "${n}"`).join(" || ");
const jobs = await pb.collection('Job_Info_Prod').getFullList({
filter,
fields: "id,Job_Number",
requestKey: null
});
jobs.forEach((j: any) => {
if (j.Job_Number !== undefined && j.Job_Number !== null && j.Job_Number !== "") {
jobMap.set(String(j.Job_Number), String(j.id));
}
});
}
let migratedNotes = 0;
for (const n of notes) {
if (!n.tags || n.tags.length === 0) continue;
let changed = false;
const newTags = n.tags.map((tag: string) => {
if (!tag.startsWith("job_id:")) return tag;
const val = tag.split(":")[1]?.trim();
if (!val || !/^\d{4}$/.test(val)) return tag;
const mappedId = jobMap.get(val);
if (!mappedId) return tag;
changed = true;
return `job_id:${mappedId}`;
});
if (changed) {
await pb.collection(NOTES_COLLECTION).update(n.id, { tags: newTags }, { requestKey: null });
migratedNotes++;
}
}
if (migratedNotes > 0) {
setStore("notes", (items) => items.map(n => {
if (!n.tags || n.tags.length === 0) return n;
let localChanged = false;
const nt = n.tags.map(tag => {
if (!tag.startsWith("job_id:")) return tag;
const val = tag.split(":")[1]?.trim();
if (!val || !/^\d{4}$/.test(val)) return tag;
const mappedId = jobMap.get(val);
if (!mappedId) return tag;
localChanged = true;
return `job_id:${mappedId}`;
});
return localChanged ? { ...n, tags: nt } : n;
}));
}
console.log(`[MIGRATION] Job tag migration complete. Updated ${migratedNotes} notes.`);
}
prefs.migratedLegacyJobIdTagsV1 = true;
await pb.collection('users').update(currentUserId, { Taskgrid_pref: prefs }, { requestKey: null });
if (pb.authStore.model) {
pb.authStore.model.Taskgrid_pref = prefs;
}
} catch (err) {
console.error("[MIGRATION] Job tag migration failed:", err);
}
};
export const initStore = async () => {
if (!pb.authStore.isValid || store.isInitializing) return;
@@ -1537,9 +1439,8 @@ export const initStore = async () => {
// Fire off background sync
await backgroundSync();
// Run one-time migrations
// Run one-time migration for legacy tags
await runLegacyTagMigration();
await runLegacyJobIdTagMigration();
// Separate Templates load (less critical)
try {