@@ -137,66 +137,68 @@ async def upgrade(settings: dict):
137
137
"the config."
138
138
)
139
139
if upgrade_from_version == upgrade_to_version :
140
- raise UpgradeError (
140
+ print (
141
141
f"Version { upgrade_from_version } to upgrade from and "
142
142
f"current version to upgrade to { upgrade_to_version } "
143
143
"are same."
144
144
)
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
148
152
)
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 )} "
183
171
)
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
+ )
198
194
)
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
+
200
202
# Update storage version
201
203
async with root_profile .session () as session :
202
204
storage = session .inject (BaseStorage )
0 commit comments