Skip to content

Commit d5bda13

Browse files
committed
Fix arangosearch views constantly showing up as migrations
1 parent bec92cf commit d5bda13

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

src/database/arangodb/schema-migration/arango-search-helpers.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,33 @@ export function calculateRequiredArangoSearchViewDropOperations(
106106
return viewsToDrop.map(value => new DropArangoSearchViewMigration({ viewName: value.name }));
107107
}
108108

109+
/**
110+
* Configures the inBackground flag
111+
*
112+
* We don'd to this initially because it won't be present in the actual view definition, and we would always see a
113+
* pending change in the migration analyzer (because it would want to add inBackground).
114+
*/
115+
export function configureForBackgroundCreation(
116+
definition: ArangoSearchViewPropertiesOptions
117+
): ArangoSearchViewPropertiesOptions {
118+
return {
119+
...definition,
120+
links: definition.links
121+
? Object.fromEntries(
122+
Object.entries(definition.links).map(([key, value]) => [
123+
key,
124+
{
125+
...value,
126+
// missing in types, see https://github.com/arangodb/arangojs/issues/759
127+
// if this is not set, creating the view would acquire an exclusive lock on the collections
128+
inBackground: true
129+
}
130+
])
131+
)
132+
: definition.links
133+
};
134+
}
135+
109136
function getPropertiesFromDefinition(
110137
definition: ArangoSearchDefinition,
111138
configuration?: ArangoSearchConfiguration
@@ -118,11 +145,7 @@ function getPropertiesFromDefinition(
118145
includeAllFields: false,
119146
storeValues: 'id',
120147
trackListPositions: false,
121-
fields: fieldDefinitionsFor(definition.rootEntityType.fields),
122-
123-
// missing in types, see https://github.com/arangodb/arangojs/issues/759
124-
// if this is not set, creating the view would acquire an exclusive lock on the collections
125-
inBackground: true
148+
fields: fieldDefinitionsFor(definition.rootEntityType.fields)
126149
} as ArangoSearchViewLink
127150
},
128151
commitIntervalMsec: configuration?.commitIntervalMsec ? configuration.commitIntervalMsec : 1000,

src/database/arangodb/schema-migration/performer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ERROR_BAD_PARAMETER,
1010
ERROR_FILE_EXISTS
1111
} from '../error-codes';
12-
import { isEqualProperties } from './arango-search-helpers';
12+
import { configureForBackgroundCreation, isEqualProperties } from './arango-search-helpers';
1313
import {
1414
CreateArangoSearchAnalyzerMigration,
1515
CreateArangoSearchViewMigration,
@@ -120,7 +120,7 @@ export class MigrationPerformer {
120120

121121
private async createArangoSearchView(migration: CreateArangoSearchViewMigration) {
122122
try {
123-
await this.db.createView(migration.viewName, migration.properties);
123+
await this.db.createView(migration.viewName, configureForBackgroundCreation(migration.properties));
124124
} catch (e) {
125125
// maybe the collection has been created in the meantime
126126
if (e.errorNum === ERROR_ARANGO_DUPLICATE_NAME) {
@@ -135,7 +135,7 @@ export class MigrationPerformer {
135135
}
136136

137137
private async updateArangoSearchView(migration: UpdateArangoSearchViewMigration) {
138-
await this.db.view(migration.viewName).replaceProperties(migration.properties);
138+
await this.db.view(migration.viewName).replaceProperties(configureForBackgroundCreation(migration.properties));
139139
}
140140

141141
private async dropArangoSearchView(migration: DropArangoSearchViewMigration) {
@@ -161,7 +161,7 @@ export class MigrationPerformer {
161161
}
162162

163163
try {
164-
await this.db.createView(migration.viewName, migration.properties);
164+
await this.db.createView(migration.viewName, configureForBackgroundCreation(migration.properties));
165165
} catch (e) {
166166
// maybe the collection has been created in the meantime
167167
if (e.errorNum === ERROR_ARANGO_DUPLICATE_NAME) {

0 commit comments

Comments
 (0)