Skip to content

Commit

Permalink
refactor: Update migrate process in CollectionReference and DocumentR…
Browse files Browse the repository at this point in the history
…eference
  • Loading branch information
alimd committed Sep 2, 2024
1 parent 9660fb2 commit 5a25ae2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/reference/src/collection-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,15 @@ export class CollectionReference<TItem extends JsonifiableObject = JsonifiableOb

if (this.context__.meta.fv === 1) {
// migrate from v1 to v2
// this.context__.meta.schemaVer = 0
this.context__.meta.fv = 2;
}

if (this.context__.meta.fv === 2) {
// migrate from v1 to v3
this.context__.meta.schemaVer ??= 1
if (this.context__.meta.schemaVer === undefined || this.context__.meta.schemaVer === 0) {
this.context__.meta.schemaVer = 1
}
delete (this.context__.meta as Dictionary)['ver'];
this.context__.meta.fv = 3;
}
Expand Down
5 changes: 4 additions & 1 deletion packages/reference/src/document-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,15 @@ export class DocumentReference<TDoc extends JsonifiableObject = JsonifiableObjec

if (this.context__.meta.fv === 1) {
// migrate from v1 to v2
// this.context__.meta.schemaVer = 0
this.context__.meta.fv = 2;
}

if (this.context__.meta.fv === 2) {
// migrate from v1 to v3
this.context__.meta.schemaVer ??= 1
if (this.context__.meta.schemaVer === undefined || this.context__.meta.schemaVer === 0) {
this.context__.meta.schemaVer = 1
}
delete (this.context__.meta as Dictionary)['ver'];
this.context__.meta.fv = 3;
}
Expand Down

0 comments on commit 5a25ae2

Please sign in to comment.