Save history
This commit is contained in:
parent
98702798fb
commit
a4fd4ef635
|
@ -3,6 +3,7 @@ import { Database, DocumentType, Document } from "@budibase/types"
|
||||||
|
|
||||||
export interface AppMigrationDoc extends Document {
|
export interface AppMigrationDoc extends Document {
|
||||||
version: string
|
version: string
|
||||||
|
history: Record<string, { runAt: number }>
|
||||||
}
|
}
|
||||||
|
|
||||||
const EXPIRY_SECONDS = Duration.fromDays(1).toSeconds()
|
const EXPIRY_SECONDS = Duration.fromDays(1).toSeconds()
|
||||||
|
@ -31,7 +32,7 @@ export async function getAppMigrationMetadata(appId: string): Promise<string> {
|
||||||
throw err
|
throw err
|
||||||
}
|
}
|
||||||
|
|
||||||
metadata = { version: "" }
|
metadata = { version: "", history: {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
await cache.store(cacheKey, metadata, EXPIRY_SECONDS)
|
await cache.store(cacheKey, metadata, EXPIRY_SECONDS)
|
||||||
|
@ -49,7 +50,15 @@ export async function updateAppMigrationMetadata({
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
const appMigrationDoc = await getFromDB(appId)
|
const appMigrationDoc = await getFromDB(appId)
|
||||||
await db.put({ ...appMigrationDoc, version })
|
const updatedMigrationDoc: AppMigrationDoc = {
|
||||||
|
...appMigrationDoc,
|
||||||
|
version,
|
||||||
|
history: {
|
||||||
|
...appMigrationDoc.history,
|
||||||
|
[version]: { runAt: Date.now() },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
await db.put(updatedMigrationDoc)
|
||||||
|
|
||||||
const cacheKey = getCacheKey(appId)
|
const cacheKey = getCacheKey(appId)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue