mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
create version graph to handle migrations (#2708)
* create version graph to handle migrations * Fix some version alpha test * connect dataVersion api * rename init fns * improve types and add tests * set data version after backup restore * chore: Add some types tests for version info * wip: More changes to versionInfo tests * wip: fix my stupid * update mocks * update runtime * chore: Fix the loop --------- Co-authored-by: Jade <2364004+Blu-J@users.noreply.github.com> Co-authored-by: J H <dragondef@gmail.com>
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { DependenciesReceipt } from "../config/setupConfig"
|
||||
import { ExtendedVersion, VersionRange } from "../exver"
|
||||
import { SetInterfaces } from "../interfaces/setupInterfaces"
|
||||
|
||||
import { ExposedStorePaths } from "../store/setupExposeStore"
|
||||
import * as T from "../types"
|
||||
import { Migrations } from "./migrations/setupMigrations"
|
||||
import { VersionGraph } from "../versionInfo/setupVersionGraph"
|
||||
import { Install } from "./setupInstall"
|
||||
import { Uninstall } from "./setupUninstall"
|
||||
|
||||
export function setupInit<Manifest extends T.Manifest, Store>(
|
||||
migrations: Migrations<Manifest, Store>,
|
||||
versions: VersionGraph<Manifest["version"]>,
|
||||
install: Install<Manifest, Store>,
|
||||
uninstall: Uninstall<Manifest, Store>,
|
||||
setInterfaces: SetInterfaces<Manifest, Store, any, any>,
|
||||
@@ -23,8 +24,19 @@ export function setupInit<Manifest extends T.Manifest, Store>(
|
||||
} {
|
||||
return {
|
||||
init: async (opts) => {
|
||||
await migrations.init(opts)
|
||||
await install.init(opts)
|
||||
const prev = await opts.effects.getDataVersion()
|
||||
if (prev) {
|
||||
await versions.migrate({
|
||||
effects: opts.effects,
|
||||
from: ExtendedVersion.parse(prev),
|
||||
to: versions.currentVersion(),
|
||||
})
|
||||
} else {
|
||||
await install.install(opts)
|
||||
await opts.effects.setDataVersion({
|
||||
version: versions.current.options.version,
|
||||
})
|
||||
}
|
||||
await setInterfaces({
|
||||
...opts,
|
||||
input: null,
|
||||
@@ -33,8 +45,18 @@ export function setupInit<Manifest extends T.Manifest, Store>(
|
||||
await setDependencies({ effects: opts.effects, input: null })
|
||||
},
|
||||
uninit: async (opts) => {
|
||||
await migrations.uninit(opts)
|
||||
await uninstall.uninit(opts)
|
||||
if (opts.nextVersion) {
|
||||
const prev = await opts.effects.getDataVersion()
|
||||
if (prev) {
|
||||
await versions.migrate({
|
||||
effects: opts.effects,
|
||||
from: ExtendedVersion.parse(prev),
|
||||
to: ExtendedVersion.parse(opts.nextVersion),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
await uninstall.uninstall(opts)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user