Updating migration name.

This commit is contained in:
mike12345567 2022-05-26 16:39:47 +01:00
parent 723b96c5a5
commit 3cdda4a1fa
5 changed files with 37 additions and 19 deletions

View File

@ -1,6 +1,6 @@
import { runQuotaMigration } from "./usageQuotas"
import * as syncApps from "./usageQuotas/syncApps"
import * as syncRows from "./usageQuotas/syncRows"
import * as syncAppRows from "./usageQuotas/syncAppRows"
/**
* Date:
@ -15,6 +15,6 @@ import * as syncRows from "./usageQuotas/syncRows"
export const run = async () => {
await runQuotaMigration(async () => {
await syncApps.run()
await syncRows.run()
await syncAppRows.run()
})
}

View File

@ -6,7 +6,7 @@ const syncRows = jest.fn()
jest.mock("../usageQuotas/syncApps", () => ({ run: syncApps }) )
jest.mock("../usageQuotas/syncRows", () => ({ run: syncRows }) )
const migration = require("../quotas1")
const migration = require("../quotas2")
describe("run", () => {
let config = new TestConfig(false)

View File

@ -0,0 +1,28 @@
import { getTenantId } from "@budibase/backend-core/tenancy"
import { getAllApps } from "@budibase/backend-core/db"
import { getUniqueRows } from "../../../utilities/usageQuota/rows"
import { quotas, QuotaUsageType, StaticQuotaName } from "@budibase/pro"
export const run = async () => {
// get all rows in all apps
// @ts-ignore
const allApps = await getAllApps({ all: true })
// @ts-ignore
const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : []
const { appRows } = await getUniqueRows(appIds)
const counts: { [key: string]: number } = {}
let rowCount = 0
Object.entries(appRows).forEach(([appId, rows]) => {
counts[appId] = rows.length
rowCount += rows.length
})
// sync row count
const tenantId = getTenantId()
console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`)
await quotas.setUsagePerApp(
counts,
StaticQuotaName.ROWS,
QuotaUsageType.STATIC
)
}

View File

@ -2,7 +2,6 @@ import { getTenantId } from "@budibase/backend-core/tenancy"
import { getAllApps } from "@budibase/backend-core/db"
import { getUniqueRows } from "../../../utilities/usageQuota/rows"
import { quotas, QuotaUsageType, StaticQuotaName } from "@budibase/pro"
import { setUsagePerApp } from "../../../../../../../budibase-pro/packages/pro/src/db/quotas"
export const run = async () => {
// get all rows in all apps
@ -10,20 +9,11 @@ export const run = async () => {
const allApps = await getAllApps({ all: true })
// @ts-ignore
const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : []
const { appRows } = await getUniqueRows(appIds)
const counts: { [key: string]: number } = {}
let rowCount = 0
Object.entries(appRows).forEach(([appId, rows]) => {
counts[appId] = rows.length
rowCount += rows.length
})
const { rows } = await getUniqueRows(appIds)
const rowCount = rows ? rows.length : 0
// sync row count
const tenantId = getTenantId()
console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`)
await quotas.setUsagePerApp(
counts,
StaticQuotaName.ROWS,
QuotaUsageType.STATIC
)
await quotas.setUsage(rowCount, StaticQuotaName.ROWS, QuotaUsageType.STATIC)
}

View File

@ -5,7 +5,7 @@ const {
// migration functions
import * as userEmailViewCasing from "./functions/userEmailViewCasing"
import * as quota1 from "./functions/quotas1"
import * as quota2 from "./functions/quotas2"
import * as appUrls from "./functions/appUrls"
import * as developerQuota from "./functions/developerQuota"
import * as publishedAppsQuota from "./functions/publishedAppsQuota"
@ -41,8 +41,8 @@ export const MIGRATIONS: Migration[] = [
},
{
type: MIGRATION_TYPES.GLOBAL,
name: "quotas_1",
fn: quota1.run,
name: "quotas_2",
fn: quota2.run,
},
{
type: MIGRATION_TYPES.APP,