Moving functions inside class.

This commit is contained in:
mike12345567 2023-11-02 18:23:16 +00:00
parent a62d82afb8
commit 00f1d2cbdc
1 changed files with 18 additions and 18 deletions

View File

@ -119,22 +119,6 @@ function getColumnMigrator(
throw new BadRequestError(`Unknown migration type`) throw new BadRequestError(`Unknown migration type`)
} }
function pickUserTableLinkSide(link: LinkDocument): LinkInfo {
if (link.doc1.tableId === InternalTable.USER_METADATA) {
return link.doc1
} else {
return link.doc2
}
}
function pickOtherTableLinkSide(link: LinkDocument): LinkInfo {
if (link.doc1.tableId === InternalTable.USER_METADATA) {
return link.doc2
} else {
return link.doc1
}
}
abstract class UserColumnMigrator implements ColumnMigrator { abstract class UserColumnMigrator implements ColumnMigrator {
constructor( constructor(
protected table: Table, protected table: Table,
@ -144,6 +128,22 @@ abstract class UserColumnMigrator implements ColumnMigrator {
abstract updateRow(row: Row, linkInfo: LinkInfo): void abstract updateRow(row: Row, linkInfo: LinkInfo): void
pickUserTableLinkSide(link: LinkDocument): LinkInfo {
if (link.doc1.tableId === InternalTable.USER_METADATA) {
return link.doc1
} else {
return link.doc2
}
}
pickOtherTableLinkSide(link: LinkDocument): LinkInfo {
if (link.doc1.tableId === InternalTable.USER_METADATA) {
return link.doc2
} else {
return link.doc1
}
}
async doMigration(): Promise<MigrationResult> { async doMigration(): Promise<MigrationResult> {
let oldTable = cloneDeep(this.table) let oldTable = cloneDeep(this.table)
let rows = await sdk.rows.fetchRaw(this.table._id!) let rows = await sdk.rows.fetchRaw(this.table._id!)
@ -154,8 +154,8 @@ abstract class UserColumnMigrator implements ColumnMigrator {
let links = await sdk.links.fetchWithDocument(this.table._id!) let links = await sdk.links.fetchWithDocument(this.table._id!)
for (let link of links) { for (let link of links) {
const userSide = pickUserTableLinkSide(link) const userSide = this.pickUserTableLinkSide(link)
const otherSide = pickOtherTableLinkSide(link) const otherSide = this.pickOtherTableLinkSide(link)
if ( if (
otherSide.tableId !== this.table._id || otherSide.tableId !== this.table._id ||
otherSide.fieldName !== this.oldColumn.name || otherSide.fieldName !== this.oldColumn.name ||