Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing test which fails in 4.6.0 only due to a change in the way we handle deletions of DefinitionContainers #181

Merged
merged 5 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "In itwinjs versions 4.6.0 and greater DefinitionContainers are now deleted as if they were DefinitionPartitions. Made a change to onDeleteModel to treat definitinocontainers as if they were definitionpartitions",
"packageName": "@itwin/imodel-transformer",
"email": "22119573+nick4598@users.noreply.github.com",
"dependentChangeType": "patch"
}
48 changes: 42 additions & 6 deletions packages/transformer/src/IModelTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from "@itwin/core-bentley";
import * as ECSchemaMetaData from "@itwin/ecschema-metadata";
import { Point3d, Transform } from "@itwin/core-geometry";
import * as coreBackendPkgJson from "@itwin/core-backend/package.json";
import {
BriefcaseManager,
ChangedECInstance,
Expand Down Expand Up @@ -448,6 +449,9 @@ export class IModelTransformer extends IModelExportHandler {
"targetScopeElementId" | "danglingReferencesBehavior"
>;

/** @see hasDefinitionContainerDeletionFeature */
private _hasDefinitionContainerDeletionFeature?: boolean;

private _isSynchronization = false;

/**
Expand Down Expand Up @@ -779,7 +783,9 @@ export class IModelTransformer extends IModelExportHandler {
);
Logger.logInfo(
TransformerLoggerCategory.IModelImporter,
`this.importer.autoExtendProjectExtents=${JSON.stringify(this.importer.options.autoExtendProjectExtents)}`
`this.importer.autoExtendProjectExtents=${JSON.stringify(
this.importer.options.autoExtendProjectExtents
)}`
);
Logger.logInfo(
TransformerLoggerCategory.IModelImporter,
Expand Down Expand Up @@ -982,6 +988,20 @@ export class IModelTransformer extends IModelExportHandler {
return this._cachedSynchronizationVersion;
}

/**
* As of itwinjs 4.6.0, definitionContainers are now deleted as if they were DefinitionPartitions as opposed to Definitions.
* This variable being true will be used to special case the deletion of DefinitionContainers the same way DefinitionPartitions are deleted.
*/
protected get hasDefinitionContainerDeletionFeature(): boolean {
if (this._hasDefinitionContainerDeletionFeature === undefined) {
this._hasDefinitionContainerDeletionFeature = Semver.satisfies(
coreBackendPkgJson.version,
"^4.6.0"
);
}
return this._hasDefinitionContainerDeletionFeature;
}

/** the changeset in the scoping element's source version found for this transformation
* @note: the version depends on whether this is a reverse synchronization or not, as
* it is stored separately for both synchronization directions.
Expand Down Expand Up @@ -1994,20 +2014,36 @@ export class IModelTransformer extends IModelExportHandler {
// It is possible and apparently occasionally sensical to delete a model without deleting its underlying element.
// - If only the model is deleted, [[initFromExternalSourceAspects]] will have already remapped the underlying element since it still exists.
// - If both were deleted, [[remapDeletedSourceEntities]] will find and remap the deleted element making this operation valid
let sql: string;
JulijaRamoskiene marked this conversation as resolved.
Show resolved Hide resolved
if (this.hasDefinitionContainerDeletionFeature) {
sql = `
SELECT 1
FROM bis.DefinitionPartition
WHERE ECInstanceId=?
UNION
SELECT 1
FROM bis.DefinitionContainer
WHERE ECInstanceId=?
`;
} else {
sql = `
SELECT 1
FROM bis.DefinitionPartition
WHERE ECInstanceId=?
`;
}
const targetModelId: Id64String =
this.context.findTargetElementId(sourceModelId);

if (!Id64.isValidId64(targetModelId)) return;

if (this.exporter.sourceDbChanges?.element.deleteIds.has(sourceModelId)) {
const isDefinitionPartition = this.targetDb.withPreparedStatement(
`
SELECT 1
FROM bis.DefinitionPartition
WHERE ECInstanceId=?
`,
sql,
(stmt) => {
stmt.bindId(1, targetModelId);
if (this.hasDefinitionContainerDeletionFeature)
JulijaRamoskiene marked this conversation as resolved.
Show resolved Hide resolved
stmt.bindId(2, targetModelId);
const val: DbResult = stmt.step();
switch (val) {
case DbResult.BE_SQLITE_ROW:
Expand Down
Loading