Skip to content

Commit 5f7b8ec

Browse files
authored
Merge pull request #2 from ianco/master
Exit if upgrade version is the same as current
2 parents 8570eaa + 0d738e8 commit 5f7b8ec

File tree

2 files changed

+60
-59
lines changed

2 files changed

+60
-59
lines changed

aries_cloudagent/commands/tests/test_upgrade.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,11 @@ async def test_upgrade_x_same_version(self):
144144
)
145145
),
146146
):
147-
with self.assertRaises(UpgradeError):
148-
await test_module.upgrade(
149-
{
150-
"upgrade.config_path": "./aries_cloudagent/commands/default_version_upgrade_config.yml",
151-
}
152-
)
147+
await test_module.upgrade(
148+
{
149+
"upgrade.config_path": "./aries_cloudagent/commands/default_version_upgrade_config.yml",
150+
}
151+
)
153152

154153
async def test_upgrade_missing_from_version(self):
155154
with async_mock.patch.object(

aries_cloudagent/commands/upgrade.py

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -137,66 +137,68 @@ async def upgrade(settings: dict):
137137
"the config."
138138
)
139139
if upgrade_from_version == upgrade_to_version:
140-
raise UpgradeError(
140+
print(
141141
f"Version {upgrade_from_version} to upgrade from and "
142142
f"current version to upgrade to {upgrade_to_version} "
143143
"are same."
144144
)
145-
if upgrade_from_version not in sorted_versions_found_in_config:
146-
raise UpgradeError(
147-
f"No upgrade configuration found for {upgrade_from_version}"
145+
else:
146+
if upgrade_from_version not in sorted_versions_found_in_config:
147+
raise UpgradeError(
148+
f"No upgrade configuration found for {upgrade_from_version}"
149+
)
150+
upgrade_from_version_index = sorted_versions_found_in_config.index(
151+
upgrade_from_version
148152
)
149-
upgrade_from_version_index = sorted_versions_found_in_config.index(
150-
upgrade_from_version
151-
)
152-
for config_from_version in sorted_versions_found_in_config[
153-
upgrade_from_version_index:
154-
]:
155-
print(f"Running upgrade process for {config_from_version}")
156-
upgrade_config = upgrade_configs.get(config_from_version)
157-
# Step 1 re-saving all BaseRecord and BaseExchangeRecord
158-
if "resave_records" in upgrade_config:
159-
resave_record_paths = upgrade_config.get("resave_records")
160-
for record_path in resave_record_paths:
161-
try:
162-
record_type = ClassLoader.load_class(record_path)
163-
except ClassNotFoundError as err:
164-
raise UpgradeError(
165-
f"Unknown Record type {record_path}"
166-
) from err
167-
if not issubclass(record_type, BaseRecord):
168-
raise UpgradeError(
169-
f"Only BaseRecord can be resaved, found: {str(record_type)}"
170-
)
171-
async with root_profile.session() as session:
172-
all_records = await record_type.query(session)
173-
for record in all_records:
174-
await record.save(
175-
session,
176-
reason="re-saving record during ACA-Py upgrade process",
177-
)
178-
if len(all_records) == 0:
179-
print(f"No records of {str(record_type)} found")
180-
else:
181-
print(
182-
f"All records of {str(record_type)} successfully re-saved"
153+
for config_from_version in sorted_versions_found_in_config[
154+
upgrade_from_version_index:
155+
]:
156+
print(f"Running upgrade process for {config_from_version}")
157+
upgrade_config = upgrade_configs.get(config_from_version)
158+
# Step 1 re-saving all BaseRecord and BaseExchangeRecord
159+
if "resave_records" in upgrade_config:
160+
resave_record_paths = upgrade_config.get("resave_records")
161+
for record_path in resave_record_paths:
162+
try:
163+
rec_type = ClassLoader.load_class(record_path)
164+
except ClassNotFoundError as err:
165+
raise UpgradeError(
166+
f"Unknown Record type {record_path}"
167+
) from err
168+
if not issubclass(rec_type, BaseRecord):
169+
raise UpgradeError(
170+
f"Only BaseRecord can be resaved, found: {str(rec_type)}"
183171
)
184-
# Step 2 Update existing records, if required
185-
if (
186-
"update_existing_records" in upgrade_config
187-
and upgrade_config.get("update_existing_records") is True
188-
):
189-
update_existing_recs_callable = (
190-
version_upgrade_config_inst.get_update_existing_func(
191-
config_from_version
192-
)
193-
)
194-
if not update_existing_recs_callable:
195-
raise UpgradeError(
196-
"No update_existing_records function "
197-
f"specified for {config_from_version}"
172+
async with root_profile.session() as session:
173+
all_records = await rec_type.query(session)
174+
for record in all_records:
175+
await record.save(
176+
session,
177+
reason="re-saving record during the upgrade process",
178+
)
179+
if len(all_records) == 0:
180+
print(f"No records of {str(rec_type)} found")
181+
else:
182+
print(
183+
f"All recs of {str(rec_type)} successfully re-saved"
184+
)
185+
# Step 2 Update existing records, if required
186+
if (
187+
"update_existing_records" in upgrade_config
188+
and upgrade_config.get("update_existing_records") is True
189+
):
190+
update_existing_recs_callable = (
191+
version_upgrade_config_inst.get_update_existing_func(
192+
config_from_version
193+
)
198194
)
199-
await update_existing_recs_callable(root_profile)
195+
if not update_existing_recs_callable:
196+
raise UpgradeError(
197+
"No update_existing_records function "
198+
f"specified for {config_from_version}"
199+
)
200+
await update_existing_recs_callable(root_profile)
201+
200202
# Update storage version
201203
async with root_profile.session() as session:
202204
storage = session.inject(BaseStorage)

0 commit comments

Comments
 (0)