@powersync/service-module-mysql 0.0.0-dev-20241219153510 → 0.0.0-dev-20250108073049
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 +19 -6
- package/dist/common/mysql-to-sqlite.js +39 -9
- package/dist/common/mysql-to-sqlite.js.map +1 -1
- package/dist/replication/BinLogStream.js +36 -32
- package/dist/replication/BinLogStream.js.map +1 -1
- package/dist/replication/MySQLConnectionManager.js +9 -1
- package/dist/replication/MySQLConnectionManager.js.map +1 -1
- package/dist/utils/mysql-utils.d.ts +2 -0
- package/dist/utils/mysql-utils.js +3 -0
- package/dist/utils/mysql-utils.js.map +1 -1
- package/package.json +7 -7
- package/src/common/mysql-to-sqlite.ts +35 -9
- package/src/replication/BinLogStream.ts +43 -33
- package/src/replication/MySQLConnectionManager.ts +8 -1
- package/src/utils/mysql-utils.ts +5 -0
- package/test/src/BinLogStream.test.ts +254 -227
- package/test/src/BinlogStreamUtils.ts +41 -22
- package/test/src/mysql-to-sqlite.test.ts +36 -19
- package/test/src/setup.ts +3 -1
- package/test/src/util.ts +4 -34
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -200,6 +200,7 @@ INSERT INTO test_data (
|
|
|
200
200
|
|
|
201
201
|
test('Date types mappings', async () => {
|
|
202
202
|
await setupTable();
|
|
203
|
+
// Timezone offset is set on the pool to +00:00
|
|
203
204
|
await connectionManager.query(`
|
|
204
205
|
INSERT INTO test_data(date_col, datetime_col, timestamp_col, time_col, year_col)
|
|
205
206
|
VALUES('2023-03-06', '2023-03-06 15:47', '2023-03-06 15:47', '15:47:00', '2023');
|
|
@@ -222,23 +223,40 @@ INSERT INTO test_data (
|
|
|
222
223
|
test('Date types edge cases mappings', async () => {
|
|
223
224
|
await setupTable();
|
|
224
225
|
|
|
225
|
-
await connectionManager.
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
226
|
+
const connection = await connectionManager.getConnection();
|
|
227
|
+
try {
|
|
228
|
+
// Disable strict mode, to allow dates such as '2024-00-00'.
|
|
229
|
+
await connection.query(`SET SESSION sql_mode=''`);
|
|
230
|
+
await connection.query(`SET SESSION time_zone='+00:00'`);
|
|
231
|
+
|
|
232
|
+
await connection.query(`INSERT INTO test_data(timestamp_col) VALUES('1970-01-01 00:00:01')`);
|
|
233
|
+
await connection.query(`INSERT INTO test_data(timestamp_col) VALUES('2038-01-19 03:14:07.499')`);
|
|
234
|
+
await connection.query(`INSERT INTO test_data(datetime_col) VALUES('1000-01-01 00:00:00')`);
|
|
235
|
+
await connection.query(`INSERT INTO test_data(datetime_col) VALUES('9999-12-31 23:59:59.499')`);
|
|
236
|
+
await connection.query(`INSERT INTO test_data(datetime_col) VALUES('0000-00-00 00:00:00')`);
|
|
237
|
+
await connection.query(`INSERT INTO test_data(datetime_col) VALUES('2024-00-00 00:00:00')`);
|
|
238
|
+
// TODO: This has a mismatch between querying directly and with Zongji.
|
|
239
|
+
// await connection.query(`INSERT INTO test_data(date_col) VALUES('2024-00-00')`);
|
|
240
|
+
|
|
241
|
+
const expectedResults = [
|
|
242
|
+
{ timestamp_col: '1970-01-01T00:00:01.000Z' },
|
|
243
|
+
{ timestamp_col: '2038-01-19T03:14:07.499Z' },
|
|
244
|
+
{ datetime_col: '1000-01-01T00:00:00.000Z' },
|
|
245
|
+
{ datetime_col: '9999-12-31T23:59:59.499Z' },
|
|
246
|
+
{ datetime_col: null },
|
|
247
|
+
{ datetime_col: null }
|
|
248
|
+
// { date_col: '2023-11-30' } or { date_col: null }?
|
|
249
|
+
];
|
|
250
|
+
|
|
251
|
+
const databaseRows = await getDatabaseRows(connectionManager, 'test_data');
|
|
252
|
+
const replicatedRows = await getReplicatedRows(expectedResults.length);
|
|
253
|
+
|
|
254
|
+
for (let i = 0; i < expectedResults.length; i++) {
|
|
255
|
+
expect(databaseRows[i]).toMatchObject(expectedResults[i]);
|
|
256
|
+
expect(replicatedRows[i]).toMatchObject(expectedResults[i]);
|
|
257
|
+
}
|
|
258
|
+
} finally {
|
|
259
|
+
connection.release;
|
|
242
260
|
}
|
|
243
261
|
});
|
|
244
262
|
|
|
@@ -282,8 +300,7 @@ async function getReplicatedRows(expectedTransactionsCount?: number): Promise<Sq
|
|
|
282
300
|
const zongji = new ZongJi({
|
|
283
301
|
host: TEST_CONNECTION_OPTIONS.hostname,
|
|
284
302
|
user: TEST_CONNECTION_OPTIONS.username,
|
|
285
|
-
password: TEST_CONNECTION_OPTIONS.password
|
|
286
|
-
timeZone: 'Z' // Ensure no auto timezone manipulation of the dates occur
|
|
303
|
+
password: TEST_CONNECTION_OPTIONS.password
|
|
287
304
|
});
|
|
288
305
|
|
|
289
306
|
const completionPromise = new Promise<SqliteRow[]>((resolve, reject) => {
|
package/test/src/setup.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { container } from '@powersync/lib-services-framework';
|
|
2
|
+
import { test_utils } from '@powersync/service-core-tests';
|
|
2
3
|
import { beforeAll } from 'vitest';
|
|
3
4
|
|
|
4
|
-
beforeAll(() => {
|
|
5
|
+
beforeAll(async () => {
|
|
5
6
|
// Executes for every test file
|
|
6
7
|
container.registerDefaults();
|
|
8
|
+
await test_utils.initMetrics();
|
|
7
9
|
});
|
package/test/src/util.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as types from '@module/types/types.js';
|
|
2
2
|
import { getMySQLVersion, isVersionAtLeast } from '@module/utils/mysql-utils.js';
|
|
3
|
-
import
|
|
4
|
-
import * as mongo_module from '@powersync/service-module-mongodb';
|
|
3
|
+
import * as mongo_storage from '@powersync/service-module-mongodb-storage';
|
|
5
4
|
import mysqlPromise from 'mysql2/promise';
|
|
6
5
|
import { env } from './env.js';
|
|
7
6
|
|
|
@@ -12,39 +11,10 @@ export const TEST_CONNECTION_OPTIONS = types.normalizeConnectionConfig({
|
|
|
12
11
|
uri: TEST_URI
|
|
13
12
|
});
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
powersync_instance_id: 'test',
|
|
19
|
-
internal_metrics_endpoint: 'unused.for.tests.com'
|
|
14
|
+
export const INITIALIZED_MONGO_STORAGE_FACTORY = mongo_storage.MongoTestStorageFactoryGenerator({
|
|
15
|
+
url: env.MONGO_TEST_URL,
|
|
16
|
+
isCI: env.CI
|
|
20
17
|
});
|
|
21
|
-
Metrics.getInstance().resetCounters();
|
|
22
|
-
|
|
23
|
-
export type StorageFactory = () => Promise<BucketStorageFactory>;
|
|
24
|
-
|
|
25
|
-
export const INITIALIZED_MONGO_STORAGE_FACTORY: StorageFactory = async () => {
|
|
26
|
-
const db = await connectMongo();
|
|
27
|
-
|
|
28
|
-
// None of the tests insert data into this collection, so it was never created
|
|
29
|
-
if (!(await db.db.listCollections({ name: db.bucket_parameters.collectionName }).hasNext())) {
|
|
30
|
-
await db.db.createCollection('bucket_parameters');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
await db.clear();
|
|
34
|
-
|
|
35
|
-
return new mongo_module.storage.MongoBucketStorage(db, { slot_name_prefix: 'test_' });
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export async function connectMongo() {
|
|
39
|
-
// Short timeout for tests, to fail fast when the server is not available.
|
|
40
|
-
// Slightly longer timeouts for CI, to avoid arbitrary test failures
|
|
41
|
-
const client = mongo_module.storage.createMongoClient(env.MONGO_TEST_URL, {
|
|
42
|
-
connectTimeoutMS: env.CI ? 15_000 : 5_000,
|
|
43
|
-
socketTimeoutMS: env.CI ? 15_000 : 5_000,
|
|
44
|
-
serverSelectionTimeoutMS: env.CI ? 15_000 : 2_500
|
|
45
|
-
});
|
|
46
|
-
return new mongo_module.storage.PowerSyncMongo(client);
|
|
47
|
-
}
|
|
48
18
|
|
|
49
19
|
export async function clearTestDb(connection: mysqlPromise.Connection) {
|
|
50
20
|
const version = await getMySQLVersion(connection);
|