Skip to content

Commit 21b3a41

Browse files
authored
Added missing changeset for sync rule package (#429)
* Changeset missing changeset for @powersync/service-sync-rules * Fixed sync rule validation query
1 parent ab106c6 commit 21b3a41

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

.changeset/blue-pillows-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/service-module-mssql': patch
3+
---
4+
5+
Fixed sync rule validation query for mssql

.changeset/rare-feet-shop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/service-sync-rules': patch
3+
---
4+
5+
Exported sql lite helper values

modules/module-mssql/src/utils/mssql.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,15 @@ export async function ensurePowerSyncCheckpointsTable(connectionManager: MSSQLCo
8888
const errors: string[] = [];
8989
try {
9090
// check if the dbo_powersync_checkpoints table exists
91-
const { recordset: checkpointsResult } = await connectionManager.query(`
91+
const { recordset: checkpointsResult } = await connectionManager.query(
92+
`
9293
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = @schema AND TABLE_NAME = @tableName;
93-
`, [
94-
{ name: 'schema', type: sql.VarChar(sql.MAX), value: connectionManager.schema },
95-
{ name: 'tableName', type: sql.VarChar(sql.MAX), value: POWERSYNC_CHECKPOINTS_TABLE },
96-
]);
94+
`,
95+
[
96+
{ name: 'schema', type: sql.VarChar(sql.MAX), value: connectionManager.schema },
97+
{ name: 'tableName', type: sql.VarChar(sql.MAX), value: POWERSYNC_CHECKPOINTS_TABLE }
98+
]
99+
);
97100
if (checkpointsResult.length > 0) {
98101
// Table already exists, check if CDC is enabled
99102
const isEnabled = await isTableEnabledForCDC({
@@ -117,7 +120,7 @@ export async function ensurePowerSyncCheckpointsTable(connectionManager: MSSQLCo
117120
// Try to create the table
118121
try {
119122
await connectionManager.query(`
120-
CREATE TABLE ${escapeIdentifier(connectionManager.schema)}.${escapeIdentifier(POWERSYNC_CHECKPOINTS_TABLE)} (
123+
CREATE TABLE ${toQualifiedTableName(connectionManager.schema, POWERSYNC_CHECKPOINTS_TABLE)} (
121124
id INT IDENTITY PRIMARY KEY,
122125
last_updated DATETIME NOT NULL DEFAULT (GETDATE())
123126
)`);
@@ -140,7 +143,7 @@ export async function ensurePowerSyncCheckpointsTable(connectionManager: MSSQLCo
140143

141144
export async function createCheckpoint(connectionManager: MSSQLConnectionManager): Promise<void> {
142145
await connectionManager.query(`
143-
MERGE ${escapeIdentifier(connectionManager.schema)}.${escapeIdentifier(POWERSYNC_CHECKPOINTS_TABLE)} AS target
146+
MERGE ${toQualifiedTableName(connectionManager.schema, POWERSYNC_CHECKPOINTS_TABLE)} AS target
144147
USING (SELECT 1 AS id) AS source
145148
ON target.id = source.id
146149
WHEN MATCHED THEN
@@ -169,10 +172,12 @@ export async function isTableEnabledForCDC(options: IsTableEnabledForCDCOptions)
169172
JOIN sys.schemas AS sch ON sch.schema_id = tbl.schema_id
170173
WHERE sch.name = @schema
171174
AND tbl.name = @tableName
172-
`, [
173-
{ name: 'schema', type: sql.VarChar(sql.MAX), value: schema },
174-
{ name: 'tableName', type: sql.VarChar(sql.MAX), value: table },
175-
]);
175+
`,
176+
[
177+
{ name: 'schema', type: sql.VarChar(sql.MAX), value: schema },
178+
{ name: 'tableName', type: sql.VarChar(sql.MAX), value: table }
179+
]
180+
);
176181
return checkResult.length > 0;
177182
}
178183

@@ -267,10 +272,12 @@ export async function getCaptureInstance(options: GetCaptureInstanceOptions): Pr
267272
WHERE sch.name = @schema
268273
AND tbl.name = @tableName
269274
AND ct.end_lsn IS NULL;
270-
`, [
271-
{ name: 'schema', type: sql.VarChar(sql.MAX), value: schema },
272-
{ name: 'tableName', type: sql.VarChar(sql.MAX), value: tableName },
273-
]);
275+
`,
276+
[
277+
{ name: 'schema', type: sql.VarChar(sql.MAX), value: schema },
278+
{ name: 'tableName', type: sql.VarChar(sql.MAX), value: tableName }
279+
]
280+
);
274281

275282
if (result.length === 0) {
276283
return null;
@@ -394,9 +401,7 @@ export async function getDebugTableInfo(options: GetDebugTableInfoOptions): Prom
394401

395402
let selectError: service_types.ReplicationError | null = null;
396403
try {
397-
await connectionManager.query(`SELECT TOP 1 * FROM @tableName`, [
398-
{ name: 'tableName', type: sql.VarChar(sql.MAX), value: toQualifiedTableName(schema, table.name) },
399-
]);
404+
await connectionManager.query(`SELECT TOP 1 * FROM ${toQualifiedTableName(schema, table.name)}`);
400405
} catch (e) {
401406
selectError = { level: 'fatal', message: e.message };
402407
}

0 commit comments

Comments
 (0)