forked from tsai/budibase
36 changed files with 226 additions and 178 deletions
@ -1,14 +0,0 @@ |
|||||
import { events, db } from "@budibase/backend-core" |
|
||||
import { App } from "@budibase/types" |
|
||||
|
|
||||
export const backfill = async (appDb: any) => { |
|
||||
const app: App = await appDb.get(db.DocumentTypes.APP_METADATA) |
|
||||
|
|
||||
if (db.isDevAppID(app.appId)) { |
|
||||
await events.app.created(app) |
|
||||
} |
|
||||
|
|
||||
if (db.isProdAppID(app.appId)) { |
|
||||
await events.app.published(app) |
|
||||
} |
|
||||
} |
|
||||
@ -1,16 +1,28 @@ |
|||||
import { events, db } from "@budibase/backend-core" |
import { events, db as dbUtils } from "@budibase/backend-core" |
||||
import { Row } from "@budibase/types" |
import { Row, App } from "@budibase/types" |
||||
import { getUniqueRows } from "../../../../utilities/usageQuota/rows" |
import { getUniqueRows } from "../../../../utilities/usageQuota/rows" |
||||
|
|
||||
// Rows is a special circumstance where we get rows across all apps
|
// Rows is a special circumstance where we get rows across all apps
|
||||
// therefore migration is performed at the global level
|
// therefore migration is performed at the global level
|
||||
|
|
||||
|
const getOldestCreatedAt = (allApps: App[]): string | undefined => { |
||||
|
const timestamps = allApps |
||||
|
.filter(app => !!app.createdAt) |
||||
|
.map(app => app.createdAt as string) |
||||
|
.sort((a, b) => new Date(a).getTime() - new Date(b).getTime()) |
||||
|
|
||||
|
if (timestamps.length) { |
||||
|
return timestamps[0] |
||||
|
} |
||||
|
} |
||||
|
|
||||
export const backfill = async () => { |
export const backfill = async () => { |
||||
const allApps = await db.getAllApps({ all: true }) |
const allApps: App[] = await dbUtils.getAllApps({ dev: true }) |
||||
|
const timestamp = getOldestCreatedAt(allApps) |
||||
const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : [] |
const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : [] |
||||
const rows: Row[] = await getUniqueRows(appIds) |
const rows: Row[] = await getUniqueRows(appIds) |
||||
const rowCount = rows ? rows.length : 0 |
const rowCount = rows ? rows.length : 0 |
||||
if (rowCount) { |
if (rowCount) { |
||||
await events.rows.created(rowCount) |
await events.rows.created(rowCount, timestamp) |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -1,6 +1,6 @@ |
|||||
export interface Document { |
export interface Document { |
||||
_id?: string |
_id?: string |
||||
_rev?: string |
_rev?: string |
||||
createdAt?: string |
createdAt?: string | number |
||||
updatedAt?: string |
updatedAt?: string |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue