@powersync/service-module-mssql 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/dist/api/MSSQLRouteAPIAdapter.d.ts +2 -2
- package/dist/api/MSSQLRouteAPIAdapter.js +3 -3
- package/dist/api/MSSQLRouteAPIAdapter.js.map +1 -1
- package/dist/common/MSSQLSourceTable.js +1 -1
- package/dist/common/MSSQLSourceTable.js.map +1 -1
- package/dist/common/MSSQLSourceTableCache.js.map +1 -1
- package/dist/common/mssqls-to-sqlite.d.ts +1 -1
- package/dist/common/mssqls-to-sqlite.js +1 -1
- package/dist/common/mssqls-to-sqlite.js.map +1 -1
- package/dist/module/MSSQLModule.js +4 -4
- package/dist/module/MSSQLModule.js.map +1 -1
- package/dist/replication/CDCPoller.d.ts +6 -6
- package/dist/replication/CDCPoller.js +3 -3
- package/dist/replication/CDCPoller.js.map +1 -1
- package/dist/replication/CDCReplicationJob.d.ts +2 -2
- package/dist/replication/CDCReplicationJob.js +3 -3
- package/dist/replication/CDCReplicationJob.js.map +1 -1
- package/dist/replication/CDCReplicator.d.ts +2 -3
- package/dist/replication/CDCReplicator.js +1 -24
- package/dist/replication/CDCReplicator.js.map +1 -1
- package/dist/replication/CDCStream.d.ts +6 -14
- package/dist/replication/CDCStream.js +17 -31
- package/dist/replication/CDCStream.js.map +1 -1
- package/dist/replication/MSSQLConnectionManager.d.ts +1 -1
- package/dist/replication/MSSQLConnectionManager.js +1 -1
- package/dist/replication/MSSQLConnectionManager.js.map +1 -1
- package/dist/replication/MSSQLConnectionManagerFactory.d.ts +1 -1
- package/dist/replication/MSSQLConnectionManagerFactory.js.map +1 -1
- package/dist/replication/MSSQLSnapshotQuery.d.ts +1 -1
- package/dist/replication/MSSQLSnapshotQuery.js +2 -2
- package/dist/replication/MSSQLSnapshotQuery.js.map +1 -1
- package/dist/utils/mssql.d.ts +4 -4
- package/dist/utils/mssql.js +2 -2
- package/dist/utils/mssql.js.map +1 -1
- package/dist/utils/schema.js +1 -1
- package/dist/utils/schema.js.map +1 -1
- package/package.json +12 -12
- package/src/api/MSSQLRouteAPIAdapter.ts +4 -4
- package/src/common/MSSQLSourceTable.ts +1 -1
- package/src/common/MSSQLSourceTableCache.ts +1 -1
- package/src/common/mssqls-to-sqlite.ts +1 -1
- package/src/module/MSSQLModule.ts +4 -4
- package/src/replication/CDCPoller.ts +9 -9
- package/src/replication/CDCReplicationJob.ts +4 -4
- package/src/replication/CDCReplicator.ts +2 -28
- package/src/replication/CDCStream.ts +30 -36
- package/src/replication/MSSQLConnectionManager.ts +2 -2
- package/src/replication/MSSQLConnectionManagerFactory.ts +1 -1
- package/src/replication/MSSQLSnapshotQuery.ts +3 -3
- package/src/utils/mssql.ts +7 -7
- package/src/utils/schema.ts +2 -2
- package/test/src/CDCStream.test.ts +5 -5
- package/test/src/CDCStreamTestContext.ts +3 -4
- package/test/src/CDCStream_resumable_snapshot.test.ts +6 -6
- package/test/src/LSN.test.ts +1 -1
- package/test/src/mssql-to-sqlite.test.ts +11 -11
- package/test/src/schema-changes.test.ts +13 -9
- package/test/src/util.ts +4 -10
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
container,
|
|
3
3
|
DatabaseConnectionError,
|
|
4
|
+
logger as defaultLogger,
|
|
4
5
|
ErrorCode,
|
|
5
6
|
Logger,
|
|
6
|
-
logger as defaultLogger,
|
|
7
7
|
ReplicationAbortedError,
|
|
8
8
|
ReplicationAssertionError
|
|
9
9
|
} from '@powersync/lib-services-framework';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
getUuidReplicaIdentityBson,
|
|
12
|
+
MetricsEngine,
|
|
13
|
+
ReplicationLagTracker,
|
|
14
|
+
SourceEntityDescriptor,
|
|
15
|
+
storage
|
|
16
|
+
} from '@powersync/service-core';
|
|
11
17
|
|
|
12
18
|
import { HydratedSyncRules, SqliteInputRow, SqliteRow, TablePattern } from '@powersync/service-sync-rules';
|
|
13
19
|
|
|
14
20
|
import { ReplicationMetric } from '@powersync/service-types';
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
21
|
+
import sql from 'mssql';
|
|
22
|
+
import { CaptureInstance } from '../common/CaptureInstance.js';
|
|
23
|
+
import { LSN } from '../common/LSN.js';
|
|
24
|
+
import { CDCToSqliteRow, toSqliteInputRow } from '../common/mssqls-to-sqlite.js';
|
|
25
|
+
import { MSSQLSourceTable } from '../common/MSSQLSourceTable.js';
|
|
26
|
+
import { MSSQLSourceTableCache } from '../common/MSSQLSourceTableCache.js';
|
|
27
|
+
import { AdditionalConfig } from '../types/types.js';
|
|
18
28
|
import {
|
|
19
29
|
checkRetentionThresholds,
|
|
20
30
|
checkSourceConfiguration,
|
|
@@ -24,14 +34,10 @@ import {
|
|
|
24
34
|
getLatestReplicatedLSN,
|
|
25
35
|
isIColumnMetadata
|
|
26
36
|
} from '../utils/mssql.js';
|
|
27
|
-
import
|
|
28
|
-
import { CDCToSqliteRow, toSqliteInputRow } from '../common/mssqls-to-sqlite.js';
|
|
29
|
-
import { LSN } from '../common/LSN.js';
|
|
30
|
-
import { MSSQLSourceTable } from '../common/MSSQLSourceTable.js';
|
|
31
|
-
import { MSSQLSourceTableCache } from '../common/MSSQLSourceTableCache.js';
|
|
37
|
+
import { getReplicationIdentityColumns, getTablesFromPattern, ResolvedTable } from '../utils/schema.js';
|
|
32
38
|
import { CDCEventHandler, CDCPoller, SchemaChange, SchemaChangeType } from './CDCPoller.js';
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
39
|
+
import { MSSQLConnectionManager } from './MSSQLConnectionManager.js';
|
|
40
|
+
import { BatchedSnapshotQuery, MSSQLSnapshotQuery, SimpleSnapshotQuery } from './MSSQLSnapshotQuery.js';
|
|
35
41
|
|
|
36
42
|
export interface CDCStreamOptions {
|
|
37
43
|
connections: MSSQLConnectionManager;
|
|
@@ -101,16 +107,7 @@ export class CDCStream {
|
|
|
101
107
|
|
|
102
108
|
public tableCache = new MSSQLSourceTableCache();
|
|
103
109
|
|
|
104
|
-
|
|
105
|
-
* Time of the oldest uncommitted change, according to the source db.
|
|
106
|
-
* This is used to determine the replication lag.
|
|
107
|
-
*/
|
|
108
|
-
private oldestUncommittedChange: Date | null = null;
|
|
109
|
-
/**
|
|
110
|
-
* Keep track of whether we have done a commit or keepalive yet.
|
|
111
|
-
* We can only compute replication lag if isStartingReplication == false, or oldestUncommittedChange is present.
|
|
112
|
-
*/
|
|
113
|
-
public isStartingReplication = true;
|
|
110
|
+
private replicationLag = new ReplicationLagTracker();
|
|
114
111
|
|
|
115
112
|
constructor(private options: CDCStreamOptions) {
|
|
116
113
|
this.logger = options.logger ?? defaultLogger;
|
|
@@ -128,6 +125,10 @@ export class CDCStream {
|
|
|
128
125
|
return this.abortSignal.aborted;
|
|
129
126
|
}
|
|
130
127
|
|
|
128
|
+
get isStartingReplication() {
|
|
129
|
+
return this.replicationLag.isStartingReplication;
|
|
130
|
+
}
|
|
131
|
+
|
|
131
132
|
get defaultSchema() {
|
|
132
133
|
return this.connections.schema;
|
|
133
134
|
}
|
|
@@ -672,10 +673,12 @@ export class CDCStream {
|
|
|
672
673
|
this.metrics.getCounter(ReplicationMetric.ROWS_REPLICATED).add(1);
|
|
673
674
|
},
|
|
674
675
|
onCommit: async (lsn: string, transactionCount: number) => {
|
|
675
|
-
const { checkpointBlocked } = await batch.commit(lsn
|
|
676
|
+
const { checkpointBlocked } = await batch.commit(lsn, {
|
|
677
|
+
oldestUncommittedChange: this.replicationLag.oldestUncommittedChange
|
|
678
|
+
});
|
|
676
679
|
this.metrics.getCounter(ReplicationMetric.TRANSACTIONS_REPLICATED).add(transactionCount);
|
|
677
680
|
if (!checkpointBlocked) {
|
|
678
|
-
this.
|
|
681
|
+
this.replicationLag.markCommitted();
|
|
679
682
|
}
|
|
680
683
|
},
|
|
681
684
|
onSchemaChange: async (schemaChange: SchemaChange) => {
|
|
@@ -800,17 +803,8 @@ export class CDCStream {
|
|
|
800
803
|
return this.syncRules.applyRowContext<never>(inputRow);
|
|
801
804
|
}
|
|
802
805
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
if (this.isStartingReplication) {
|
|
806
|
-
// We don't have anything to compute replication lag with yet.
|
|
807
|
-
return undefined;
|
|
808
|
-
} else {
|
|
809
|
-
// We don't have any uncommitted changes, so replication is up-to-date.
|
|
810
|
-
return 0;
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
return Date.now() - this.oldestUncommittedChange.getTime();
|
|
806
|
+
getReplicationLagMillis(): number | undefined {
|
|
807
|
+
return this.replicationLag.getLagMillis();
|
|
814
808
|
}
|
|
815
809
|
|
|
816
810
|
private touch() {
|
|
@@ -823,7 +817,7 @@ export class CDCStream {
|
|
|
823
817
|
* Creates an update in the source database to ensure regular checkpoints via the CDC
|
|
824
818
|
*/
|
|
825
819
|
public async keepAlive() {
|
|
826
|
-
if (!this.isStartingReplication && !this.stopped) {
|
|
820
|
+
if (!this.replicationLag.isStartingReplication && !this.stopped) {
|
|
827
821
|
await createCheckpoint(this.connections);
|
|
828
822
|
}
|
|
829
823
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseObserver, logger } from '@powersync/lib-services-framework';
|
|
2
|
-
import sql from 'mssql';
|
|
3
|
-
import { NormalizedMSSQLConnectionConfig } from '../types/types.js';
|
|
4
2
|
import { POWERSYNC_VERSION } from '@powersync/service-core';
|
|
3
|
+
import sql from 'mssql';
|
|
5
4
|
import { MSSQLParameter } from '../types/mssql-data-types.js';
|
|
5
|
+
import { NormalizedMSSQLConnectionConfig } from '../types/types.js';
|
|
6
6
|
import { addParameters } from '../utils/mssql.js';
|
|
7
7
|
|
|
8
8
|
export const DEFAULT_SCHEMA = 'dbo';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { logger } from '@powersync/lib-services-framework';
|
|
2
|
+
import sql from 'mssql';
|
|
2
3
|
import { ResolvedMSSQLConnectionConfig } from '../types/types.js';
|
|
3
4
|
import { MSSQLConnectionManager } from './MSSQLConnectionManager.js';
|
|
4
|
-
import sql from 'mssql';
|
|
5
5
|
|
|
6
6
|
export class MSSQLConnectionManagerFactory {
|
|
7
7
|
private readonly connectionManagers: Set<MSSQLConnectionManager>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { bson, ColumnDescriptor, SourceTable } from '@powersync/service-core';
|
|
2
1
|
import { ServiceAssertionError } from '@powersync/lib-services-framework';
|
|
3
|
-
import {
|
|
2
|
+
import { bson, ColumnDescriptor, SourceTable } from '@powersync/service-core';
|
|
4
3
|
import sql from 'mssql';
|
|
5
|
-
import { escapeIdentifier } from '../utils/mssql.js';
|
|
6
4
|
import { MSSQLSourceTable } from '../common/MSSQLSourceTable.js';
|
|
5
|
+
import { MSSQLBaseType } from '../types/mssql-data-types.js';
|
|
6
|
+
import { escapeIdentifier } from '../utils/mssql.js';
|
|
7
7
|
|
|
8
8
|
export interface MSSQLSnapshotQuery {
|
|
9
9
|
initialize(): Promise<void>;
|
package/src/utils/mssql.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
2
|
+
import * as sync_rules from '@powersync/service-sync-rules';
|
|
3
|
+
import { SqlSyncRules, TablePattern } from '@powersync/service-sync-rules';
|
|
4
|
+
import * as service_types from '@powersync/service-types';
|
|
1
5
|
import sql from 'mssql';
|
|
2
6
|
import { coerce, gte } from 'semver';
|
|
3
|
-
import {
|
|
4
|
-
import { retryOnDeadlock } from './deadlock.js';
|
|
5
|
-
import { MSSQLConnectionManager } from '../replication/MSSQLConnectionManager.js';
|
|
7
|
+
import { CaptureInstance } from '../common/CaptureInstance.js';
|
|
6
8
|
import { LSN } from '../common/LSN.js';
|
|
7
9
|
import { MSSQLSourceTable } from '../common/MSSQLSourceTable.js';
|
|
10
|
+
import { MSSQLConnectionManager } from '../replication/MSSQLConnectionManager.js';
|
|
8
11
|
import { MSSQLParameter } from '../types/mssql-data-types.js';
|
|
9
|
-
import
|
|
10
|
-
import { SqlSyncRules, TablePattern } from '@powersync/service-sync-rules';
|
|
12
|
+
import { retryOnDeadlock } from './deadlock.js';
|
|
11
13
|
import {
|
|
12
14
|
getPendingSchemaChanges,
|
|
13
15
|
getReplicationIdentityColumns,
|
|
14
16
|
ReplicationIdentityColumnsResult,
|
|
15
17
|
ResolvedTable
|
|
16
18
|
} from './schema.js';
|
|
17
|
-
import * as service_types from '@powersync/service-types';
|
|
18
|
-
import { CaptureInstance } from '../common/CaptureInstance.js';
|
|
19
19
|
|
|
20
20
|
export const POWERSYNC_CHECKPOINTS_TABLE = '_powersync_checkpoints';
|
|
21
21
|
|
package/src/utils/schema.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
1
2
|
import { SourceEntityDescriptor } from '@powersync/service-core';
|
|
2
3
|
import { TablePattern } from '@powersync/service-sync-rules';
|
|
4
|
+
import sql from 'mssql';
|
|
3
5
|
import { MSSQLConnectionManager } from '../replication/MSSQLConnectionManager.js';
|
|
4
6
|
import { MSSQLColumnDescriptor } from '../types/mssql-data-types.js';
|
|
5
|
-
import sql from 'mssql';
|
|
6
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
7
7
|
|
|
8
8
|
export interface GetColumnsOptions {
|
|
9
9
|
connectionManager: MSSQLConnectionManager;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getLatestLSN } from '@module/utils/mssql.js';
|
|
2
|
+
import { storage } from '@powersync/service-core';
|
|
2
3
|
import { METRICS_HELPER, putOp, removeOp } from '@powersync/service-core-tests';
|
|
3
4
|
import { ReplicationMetric } from '@powersync/service-types';
|
|
4
|
-
import { createTestTable, describeWithStorage, insertTestData, waitForPendingCDCChanges } from './util.js';
|
|
5
|
-
import { storage } from '@powersync/service-core';
|
|
6
|
-
import { CDCStreamTestContext } from './CDCStreamTestContext.js';
|
|
7
|
-
import { getLatestLSN } from '@module/utils/mssql.js';
|
|
8
5
|
import sql from 'mssql';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
7
|
+
import { CDCStreamTestContext } from './CDCStreamTestContext.js';
|
|
8
|
+
import { createTestTable, describeWithStorage, insertTestData, waitForPendingCDCChanges } from './util.js';
|
|
9
9
|
|
|
10
10
|
const BASIC_SYNC_RULES = `
|
|
11
11
|
bucket_definitions:
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CDCStream, CDCStreamOptions } from '@module/replication/CDCStream.js';
|
|
2
|
+
import { MSSQLConnectionManager } from '@module/replication/MSSQLConnectionManager.js';
|
|
1
3
|
import {
|
|
2
4
|
BucketStorageFactory,
|
|
3
5
|
createCoreReplicationMetrics,
|
|
@@ -10,10 +12,8 @@ import {
|
|
|
10
12
|
updateSyncRulesFromYaml
|
|
11
13
|
} from '@powersync/service-core';
|
|
12
14
|
import { bucketRequest, METRICS_HELPER, test_utils } from '@powersync/service-core-tests';
|
|
13
|
-
import { clearTestDb, getClientCheckpoint, TEST_CONNECTION_OPTIONS } from './util.js';
|
|
14
|
-
import { CDCStream, CDCStreamOptions } from '@module/replication/CDCStream.js';
|
|
15
|
-
import { MSSQLConnectionManager } from '@module/replication/MSSQLConnectionManager.js';
|
|
16
15
|
import timers from 'timers/promises';
|
|
16
|
+
import { clearTestDb, getClientCheckpoint, TEST_CONNECTION_OPTIONS } from './util.js';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Tests operating on the change data capture need to configure the stream and manage asynchronous
|
|
@@ -156,7 +156,6 @@ export class CDCStreamTestContext implements AsyncDisposable {
|
|
|
156
156
|
throw new Error('Call replicateSnapshot() before startStreaming()');
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
this.cdcStream.isStartingReplication = true;
|
|
160
159
|
this.streamPromise = this.cdcStream.streamChanges();
|
|
161
160
|
// Wait for the replication to start before returning.
|
|
162
161
|
// This avoids a bunch of unpredictable race conditions that appear in testing
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { TestStorageConfig, TestStorageFactory } from '@powersync/service-core';
|
|
1
|
+
import { getLatestLSN } from '@module/utils/mssql.js';
|
|
2
|
+
import { logger, ReplicationAbortedError } from '@powersync/lib-services-framework';
|
|
3
|
+
import { TestStorageConfig } from '@powersync/service-core';
|
|
5
4
|
import { METRICS_HELPER } from '@powersync/service-core-tests';
|
|
6
5
|
import { ReplicationMetric } from '@powersync/service-types';
|
|
7
6
|
import * as timers from 'node:timers/promises';
|
|
8
|
-
import {
|
|
7
|
+
import { describe, expect, test } from 'vitest';
|
|
9
8
|
import { CDCStreamTestContext } from './CDCStreamTestContext.js';
|
|
10
|
-
import {
|
|
9
|
+
import { env } from './env.js';
|
|
10
|
+
import { createTestTableWithBasicId, describeWithStorage, waitForPendingCDCChanges } from './util.js';
|
|
11
11
|
|
|
12
12
|
describe.skipIf(!(env.CI || env.SLOW_TESTS))('batch replication', function () {
|
|
13
13
|
describeWithStorage({ timeout: 240_000 }, function (config) {
|
package/test/src/LSN.test.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import { CDCToSqliteRow, toSqliteInputRow } from '@module/common/mssqls-to-sqlite.js';
|
|
2
|
+
import { CDC_SCHEMA } from '@module/common/MSSQLSourceTable.js';
|
|
3
|
+
import { MSSQLConnectionManager } from '@module/replication/MSSQLConnectionManager.js';
|
|
4
|
+
import {
|
|
5
|
+
escapeIdentifier,
|
|
6
|
+
getCaptureInstances,
|
|
7
|
+
getLatestLSN,
|
|
8
|
+
getLatestReplicatedLSN,
|
|
9
|
+
toQualifiedTableName
|
|
10
|
+
} from '@module/utils/mssql.js';
|
|
1
11
|
import {
|
|
2
12
|
applyRowContext,
|
|
3
13
|
CompatibilityContext,
|
|
@@ -5,6 +15,7 @@ import {
|
|
|
5
15
|
SqliteInputRow,
|
|
6
16
|
TimeValuePrecision
|
|
7
17
|
} from '@powersync/service-sync-rules';
|
|
18
|
+
import sql from 'mssql';
|
|
8
19
|
import { afterAll, beforeEach, describe, expect, test } from 'vitest';
|
|
9
20
|
import {
|
|
10
21
|
clearTestDb,
|
|
@@ -13,17 +24,6 @@ import {
|
|
|
13
24
|
TEST_CONNECTION_OPTIONS,
|
|
14
25
|
waitForPendingCDCChanges
|
|
15
26
|
} from './util.js';
|
|
16
|
-
import { CDCToSqliteRow, toSqliteInputRow } from '@module/common/mssqls-to-sqlite.js';
|
|
17
|
-
import { MSSQLConnectionManager } from '@module/replication/MSSQLConnectionManager.js';
|
|
18
|
-
import {
|
|
19
|
-
escapeIdentifier,
|
|
20
|
-
getCaptureInstances,
|
|
21
|
-
getLatestLSN,
|
|
22
|
-
getLatestReplicatedLSN,
|
|
23
|
-
toQualifiedTableName
|
|
24
|
-
} from '@module/utils/mssql.js';
|
|
25
|
-
import sql from 'mssql';
|
|
26
|
-
import { CDC_SCHEMA } from '@module/common/MSSQLSourceTable.js';
|
|
27
27
|
|
|
28
28
|
describe('MSSQL Data Types Tests', () => {
|
|
29
29
|
const connectionManager = new MSSQLConnectionManager(TEST_CONNECTION_OPTIONS, {});
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { putOp, removeOp } from '@powersync/service-core-tests';
|
|
2
|
-
import { describe, expect, test, vi } from 'vitest';
|
|
3
1
|
import { storage } from '@powersync/service-core';
|
|
2
|
+
import { putOp, removeOp } from '@powersync/service-core-tests';
|
|
4
3
|
import sql from 'mssql';
|
|
4
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
5
5
|
|
|
6
|
+
import { SchemaChangeType } from '@module/replication/CDCPoller.js';
|
|
7
|
+
import { getLatestLSN, toQualifiedTableName } from '@module/utils/mssql.js';
|
|
8
|
+
import { logger } from '@powersync/lib-services-framework';
|
|
6
9
|
import { CDCStreamTestContext } from './CDCStreamTestContext.js';
|
|
7
10
|
import {
|
|
8
11
|
createTestTableWithBasicId,
|
|
@@ -14,9 +17,6 @@ import {
|
|
|
14
17
|
renameTable,
|
|
15
18
|
waitForPendingCDCChanges
|
|
16
19
|
} from './util.js';
|
|
17
|
-
import { getLatestLSN, toQualifiedTableName } from '@module/utils/mssql.js';
|
|
18
|
-
import { SchemaChangeType } from '@module/replication/CDCPoller.js';
|
|
19
|
-
import { logger } from '@powersync/lib-services-framework';
|
|
20
20
|
|
|
21
21
|
describe('MSSQL Schema Changes Tests', () => {
|
|
22
22
|
describeWithStorage({ timeout: 60_000 }, defineSchemaChangesTests);
|
|
@@ -459,10 +459,14 @@ function defineSchemaChangesTests(config: storage.TestStorageConfig) {
|
|
|
459
459
|
|
|
460
460
|
async function expectedSchemaChange(spy: any, type: SchemaChangeType) {
|
|
461
461
|
logger.info(`Test Assertion: Waiting for schema change: ${type}`);
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
462
|
+
try {
|
|
463
|
+
await vi.waitFor(() => expect(spy).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ type })), {
|
|
464
|
+
timeout: 55000
|
|
465
|
+
});
|
|
466
|
+
} catch (error) {
|
|
467
|
+
// The error message thrown here is extremely verbose and not particularly helpful
|
|
468
|
+
throw new Error(`Test Assertion: Timeout waiting for schema change: ${type}`);
|
|
469
|
+
}
|
|
466
470
|
const promises = spy.mock.results.filter((r: any) => r.type === 'return').map((r: any) => r.value);
|
|
467
471
|
|
|
468
472
|
await Promise.all(promises.map((p: Promise<unknown>) => expect(p).resolves.toBeUndefined()));
|
package/test/src/util.ts
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
import * as types from '@module/types/types.js';
|
|
2
2
|
import { logger } from '@powersync/lib-services-framework';
|
|
3
|
-
import {
|
|
4
|
-
BucketStorageFactory,
|
|
5
|
-
InternalOpId,
|
|
6
|
-
ReplicationCheckpoint,
|
|
7
|
-
TestStorageConfig,
|
|
8
|
-
TestStorageFactory
|
|
9
|
-
} from '@powersync/service-core';
|
|
3
|
+
import { BucketStorageFactory, InternalOpId, ReplicationCheckpoint, TestStorageConfig } from '@powersync/service-core';
|
|
10
4
|
|
|
11
5
|
import * as mongo_storage from '@powersync/service-module-mongodb-storage';
|
|
12
6
|
import * as postgres_storage from '@powersync/service-module-postgres-storage';
|
|
13
7
|
|
|
14
|
-
import {
|
|
15
|
-
import { env } from './env.js';
|
|
8
|
+
import { LSN } from '@module/common/LSN.js';
|
|
16
9
|
import { MSSQLConnectionManager } from '@module/replication/MSSQLConnectionManager.js';
|
|
17
10
|
import { createCheckpoint, escapeIdentifier, getLatestLSN, toQualifiedTableName } from '@module/utils/mssql.js';
|
|
18
11
|
import sql from 'mssql';
|
|
19
12
|
import { v4 as uuid } from 'uuid';
|
|
20
|
-
import {
|
|
13
|
+
import { describe, TestOptions } from 'vitest';
|
|
14
|
+
import { env } from './env.js';
|
|
21
15
|
|
|
22
16
|
export const TEST_URI = env.MSSQL_TEST_URI;
|
|
23
17
|
|