From 40983c53744a66388508a10b9b2446b353b09eb7 Mon Sep 17 00:00:00 2001
From: RohitPtnkr1996 <111407262+RohitPtnkr1996@users.noreply.github.com>
Date: Fri, 30 May 2025 14:55:05 +0530
Subject: [PATCH 1/2] Added tests
---
core/backend/src/test/imodel/IModel.test.ts | 97 +++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/core/backend/src/test/imodel/IModel.test.ts b/core/backend/src/test/imodel/IModel.test.ts
index 69a4e8225afc..8262df4ac332 100644
--- a/core/backend/src/test/imodel/IModel.test.ts
+++ b/core/backend/src/test/imodel/IModel.test.ts
@@ -2956,4 +2956,101 @@ describe("iModel", () => {
imodel.close();
});
+
+ function assertSchemaVersion(imodel: IModelDb, schemaName: string, expectedVersion: string) {
+ const schemaProps = imodel.getSchemaProps(schemaName);
+ assert.isDefined(schemaProps);
+ assert.strictEqual(schemaProps.version, expectedVersion);
+ }
+
+ async function assertClassProperty(imodel: IModelDb, classNameFullName: string, properties: any) {
+ const testClass = await imodel.schemaContext.getSchemaItem(classNameFullName, EntityClass);
+ assert.isDefined(testClass);
+ for (const prop of properties) {
+ const property = await testClass?.getProperty(prop.propName);
+ assert.equal(prop.propertyExists, property !== undefined, `Property ${prop.propName} existence check failed for class ${classNameFullName}`);
+ }
+ }
+
+ it("Major schema updates should only work for dynamic schemas", async () => {
+ const imodelPath = IModelTestUtils.prepareOutputFile("IModel", "majorschemaupgrade.bim");
+
+ // Remove the file if it already exists
+ if (IModelJsFs.existsSync(imodelPath))
+ IModelJsFs.unlinkSync(imodelPath);
+
+ // Create a new empty snapshot iModel
+ const testImodel = SnapshotDb.createEmpty(imodelPath, { rootSubject: { name: "majorschemaupgrade" } });
+
+ // Import initial schema and verify version
+ await testImodel.importSchemaStrings([`
+
+
+
+
+ bis:PhysicalElement
+
+
+ `]);
+ assertSchemaVersion(testImodel, "TestSchema", "01.00.00");
+ await assertClassProperty(testImodel, "TestSchema.TestClass", [{ propName: "PropToDelete", propertyExists: true }]);
+
+ // Attempt to delete a property 'PropToDelete' in a major schema update on a non-dynamic schema (should fail)
+ try {
+ await testImodel.importSchemaStrings([`
+
+
+
+
+ bis:PhysicalElement
+
+ `]);
+ assert.fail("Expected an error to be thrown when trying to delete a property in a major schema update on a non-dynamic schema.");
+ } catch {
+ // Confirm schema version and property still exist
+ assertSchemaVersion(testImodel, "TestSchema", "01.00.00");
+ await assertClassProperty(testImodel, "TestSchema.TestClass", [{ propName: "PropToDelete", propertyExists: true }]);
+ }
+
+ // Make the schema dynamic and verify version and properties
+ await testImodel.importSchemaStrings([`
+
+
+
+
+
+
+
+
+
+ bis:PhysicalElement
+
+
+
+ `]);
+ assertSchemaVersion(testImodel, "TestSchema", "01.00.01");
+ await assertClassProperty(testImodel, "TestSchema.TestClass", [{ propName: "PropToDelete", propertyExists: true }, { propName: "AnotherProperty", propertyExists: true }]);
+
+ // Now try to delete a property 'PropToDelete' in a major schema update on a dynamic schema (should succeed)
+ try {
+ await testImodel.importSchemaStrings([`
+
+
+
+
+
+
+
+
+
+ bis:PhysicalElement
+
+
+ `]);
+ assertSchemaVersion(testImodel, "TestSchema", "02.00.01");
+ await assertClassProperty(testImodel, "TestSchema.TestClass", [{ propName: "PropToDelete", propertyExists: false }, { propName: "AnotherProperty", propertyExists: true }]);
+ } catch {
+ assert.fail("Expected no error to be thrown when deleting a property in a major schema update on a dynamic schema.");
+ }
+ });
});
From ec15f2dd16ac2ba9d3235b798246ffbe08c371c6 Mon Sep 17 00:00:00 2001
From: RohitPtnkr1996 <111407262+RohitPtnkr1996@users.noreply.github.com>
Date: Fri, 30 May 2025 14:55:38 +0530
Subject: [PATCH 2/2] Added changelog
---
...-schema-upgrade-investigation_2025-05-30-09-25.json | 10 ++++++++++
1 file changed, 10 insertions(+)
create mode 100644 common/changes/@itwin/core-backend/rohitptnkr-major-schema-upgrade-investigation_2025-05-30-09-25.json
diff --git a/common/changes/@itwin/core-backend/rohitptnkr-major-schema-upgrade-investigation_2025-05-30-09-25.json b/common/changes/@itwin/core-backend/rohitptnkr-major-schema-upgrade-investigation_2025-05-30-09-25.json
new file mode 100644
index 000000000000..99b35bb89b62
--- /dev/null
+++ b/common/changes/@itwin/core-backend/rohitptnkr-major-schema-upgrade-investigation_2025-05-30-09-25.json
@@ -0,0 +1,10 @@
+{
+ "changes": [
+ {
+ "packageName": "@itwin/core-backend",
+ "comment": "",
+ "type": "none"
+ }
+ ],
+ "packageName": "@itwin/core-backend"
+}
\ No newline at end of file