Migrate core infrastructure to VoidLibrary
This commit is contained in:
1 parent
53801f2b53
commit
2bdb63766d
65 files changed
+16109
-12011
No files matched your search
@@ -0,0 +1,73 @@
|
||||
#include "echoion/core/state/StateMigration.hpp"
|
||||
#include "echoion/core/state/StateSerializer.hpp"
|
||||
#include <Void/Data/Json.hpp>
|
||||
#include <Void/Data/Reflect.hpp>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
Api::Result<StateV1> StateMigration::migrate(uint32_t fromVersion,
|
||||
const std::string& jsonData)
|
||||
{
|
||||
// Migration chain: fromVersion -> ... -> CURRENT_VERSION
|
||||
// For now, only V0 -> V1 is implemented
|
||||
// Future: V1 -> V2, V2 -> V3, etc.
|
||||
|
||||
if (fromVersion == 0) {
|
||||
auto parsed = Void::Json::parse(jsonData);
|
||||
if (!parsed) {
|
||||
return std::unexpected(Api::Error{Api::ErrorCode::ParseError,
|
||||
"Failed to parse V0 state"});
|
||||
}
|
||||
auto v0 = Void::Json::from_json<StateV0>(*parsed);
|
||||
if (!v0) {
|
||||
return std::unexpected(Api::Error{Api::ErrorCode::ParseError,
|
||||
"Failed to parse V0 state"});
|
||||
}
|
||||
return fromV0(*v0);
|
||||
}
|
||||
|
||||
// Add more migrations here as versions evolve
|
||||
// if (fromVersion == 1) { return fromV1(...); }
|
||||
|
||||
return std::unexpected(Api::Error{
|
||||
Api::ErrorCode::IncompatibleVersion,
|
||||
std::format("No migration path from version {}", fromVersion)});
|
||||
}
|
||||
|
||||
StateV1 StateMigration::fromV0(const StateV0& v0)
|
||||
{
|
||||
StateV1 v1;
|
||||
|
||||
// Migrate queue
|
||||
for (const auto& trackId : v0.trackIds) {
|
||||
StateV1::QueueEntryState entry;
|
||||
entry.track.id = trackId;
|
||||
entry.track.title = "Unknown";
|
||||
entry.track.artist = "Unknown";
|
||||
v1.queue.push_back(std::move(entry));
|
||||
}
|
||||
|
||||
// Migrate playback state
|
||||
if (!v1.queue.empty()) {
|
||||
StateV1::PlaybackState playback;
|
||||
playback.currentTrack = v1.queue[0].track;
|
||||
playback.volume = v0.volume;
|
||||
v1.playback = std::move(playback);
|
||||
v1.hasPlayback = true;
|
||||
}
|
||||
|
||||
v1.version = 1;
|
||||
v1.savedAt = StateSerializer::getCurrentTimestampISO8601();
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
bool StateMigration::canMigrate(uint32_t fromVersion)
|
||||
{
|
||||
return fromVersion >= StateSerializer::getMinimumSupportedVersion() &&
|
||||
fromVersion < StateSerializer::getCurrentVersion();
|
||||
}
|
||||
|
||||
} // namespace Echoion::Core
|
||||
Reference in new issue
Block a user