Please tell me I'm doing something simple wrong. I want to write a perl script which will apply a new schema to a DB. So, after this and that, I ended up with the script below. No matter what I do, the $databaseObj->Upgrade($schemaRevObj); line always fails with:
"This operation cannot proceed until the metadata has been loaded."
Yet, if I apply the exact same change to the DB manually, it works just fine.
I thought it was a result of using the new designer on a Win7 box, but I get the same results if I checkout/change/checkin the schema on an older XP machine with the 7.0.1 designer installed.
I've tested all the error paths and all the functional paths, up to the referenced failing line, appear to working just fine. I can watch the code loop through the schemas, find the proper revs, etc.
Thanks for any insight!
Jonathan Allan
Relevant Script Fragments:
$adminSession = CQAdminSession::Build; # open up an admin session
$adminSession->Logon($dest_login,$dest_passwd,$dest_dbset); # Login as admin user
$databaseObj = $adminSession->GetDatabase($dest_db); # Try to find the database
$schemaRevObj = $databaseObj->GetSchemaRev; # currently used schema version
$in_use_rev = -1; # invalid value in case next conversion fails
$in_use_rev = int($schemaRevObj->GetRevID); # Get the number for later work
if ( $in_use_rev < $end_ver ) {
print "Upgrading ($dest_db) to version ($end_ver) from version ($in_use_rev)...\n";
$schemasObj = $adminSession->GetSchemas;
$found_schema = 0;
for ( $x = 0; $x < $schemasObj->Count; $x++ ) {
$schemaObj = $schemasObj->Item($x);
$schemaName = $schemaObj->GetName;
if ( $preview ) { print "Schema $x is named $schemaName.\n"; }
if ( $schemaName eq $schema_name ) { # Found the schema we want to update?
$schemaRevsObj = $schemaObj->GetSchemaRevs;
$nrevs = $schemaRevsObj->Count; # number of revs for this schema, 0 offset
if ( $preview ) { print "nrevs=$nrevs.\n"; }
if ( $end_ver > $nrevs ) {
print "ERROR: The schema repository ($dest_dbset) only has ($nrevs) revisions for the ($schema_name) schema. Cannot upgrade ($dest_db) database to version ($end_ver).\n";
goto FINISH;
}
$schemaRevObj = $schemaRevsObj->Item($end_ver - 1);
$found_schema = 1;
last;
}
}
- Push the changes.
if ( ! $preview ) {
$databaseObj->Upgrade($schemaRevObj);
print "Did the update.\n";
} else {
print "Database ($dest_db) not upgraded in preview mode.\n";
}
} else {
print "ERROR: Unable to find a schema named ($schema_name) in the destination schema repository ($dest_dbset).\n";
}
} else {
print "Destination db ($dest_db) version is up to date, in use schema rev was: $in_use_rev.\n";
}
FINISH:
- Clean up from the session