Assert if NESTED_SETTINGS migration is missing for an intermediate version

- Fixes early load during NESTED_SETTINGS construction within
  SCHEMATIC_SETTINGS, now failing due to missing migrations at that
  object construction point
- Adds missing (NOOP) migration for NET_SETTINGS schema versions 1 -> 2
This commit is contained in:
JamesJCode 2024-05-05 19:08:55 +01:00
parent 89433afb47
commit 658eb1d338
6 changed files with 29 additions and 21 deletions

View File

@ -54,7 +54,7 @@ static int getInSchUnits( const nlohmann::json& aObj, const std::string& aKey, i
NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath )
NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath, false )
{
m_DefaultNetClass = std::make_shared<NETCLASS>( NETCLASS::Default );
m_DefaultNetClass->SetDescription( _( "This is the default net class." ) );
@ -298,6 +298,7 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
{} ) );
registerMigration( 0, 1, std::bind( &NET_SETTINGS::migrateSchema0to1, this ) );
registerMigration( 1, 2, std::bind( &NET_SETTINGS::migrateSchema1to2, this ) );
registerMigration( 2, 3, std::bind( &NET_SETTINGS::migrateSchema2to3, this ) );
}
@ -360,6 +361,12 @@ bool NET_SETTINGS::migrateSchema0to1()
}
bool NET_SETTINGS::migrateSchema1to2()
{
return true;
}
bool NET_SETTINGS::migrateSchema2to3()
{
if( m_internals->contains( "classes" ) && m_internals->At( "classes" ).is_array() )

View File

@ -674,29 +674,29 @@ bool JSON_SETTINGS::Migrate()
while( filever < m_schemaVersion )
{
wxASSERT( m_migrators.count( filever ) > 0 );
if( !m_migrators.count( filever ) )
{
wxLogTrace( traceSettings, wxT( "Migrator missing for %s version %d!" ),
typeid( *this ).name(), filever );
filever++;
return false;
}
std::pair<int, std::function<bool()>> pair = m_migrators.at( filever );
if( pair.second() )
{
wxLogTrace( traceSettings, wxT( "Migrated %s from %d to %d" ), typeid( *this ).name(),
filever, pair.first );
filever = pair.first;
m_internals->At( "meta.version" ) = filever;
}
else
{
std::pair<int, std::function<bool()>> pair = m_migrators.at( filever );
if( pair.second() )
{
wxLogTrace( traceSettings, wxT( "Migrated %s from %d to %d" ),
typeid( *this ).name(), filever, pair.first );
filever = pair.first;
m_internals->At( "meta.version" ) = filever;
}
else
{
wxLogTrace( traceSettings, wxT( "Migration failed for %s from %d to %d" ),
typeid( *this ).name(), filever, pair.first );
return false;
}
wxLogTrace( traceSettings, wxT( "Migration failed for %s from %d to %d" ),
typeid( *this ).name(), filever, pair.first );
return false;
}
}

View File

@ -26,11 +26,11 @@
NESTED_SETTINGS::NESTED_SETTINGS( const std::string& aName, int aVersion, JSON_SETTINGS* aParent,
const std::string& aPath ) :
const std::string& aPath, bool aLoadFromFile ) :
JSON_SETTINGS( aName, SETTINGS_LOC::NESTED, aVersion ),
m_parent( aParent ), m_path( aPath )
{
SetParent( aParent );
SetParent( aParent, aLoadFromFile );
}

View File

@ -37,7 +37,7 @@ const int schSettingsSchemaVersion = 1;
SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) :
NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath ),
NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath, false ),
m_DefaultLineWidth( DEFAULT_LINE_WIDTH_MILS * schIUScale.IU_PER_MILS ),
m_DefaultTextSize( DEFAULT_TEXT_SIZE * schIUScale.IU_PER_MILS ),
m_LabelSizeRatio( DEFAULT_LABEL_SIZE_RATIO ),

View File

@ -96,6 +96,7 @@ public:
private:
bool migrateSchema0to1();
bool migrateSchema1to2();
bool migrateSchema2to3();
// TODO: Add diff pairs, bus information, etc.

View File

@ -32,7 +32,7 @@ class KICOMMON_API NESTED_SETTINGS : public JSON_SETTINGS
{
public:
NESTED_SETTINGS( const std::string& aName, int aSchemaVersion, JSON_SETTINGS* aParent,
const std::string& aPath );
const std::string& aPath, bool aLoadFromFile = true );
virtual ~NESTED_SETTINGS();