@powersync/service-module-mysql 0.0.0-dev-20241015210820

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.
Files changed (96) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/LICENSE +67 -0
  3. package/README.md +3 -0
  4. package/dev/.env.template +2 -0
  5. package/dev/README.md +9 -0
  6. package/dev/config/sync_rules.yaml +12 -0
  7. package/dev/docker/mysql/docker-compose.yaml +17 -0
  8. package/dev/docker/mysql/init-scripts/my.cnf +9 -0
  9. package/dev/docker/mysql/init-scripts/mysql.sql +38 -0
  10. package/dist/api/MySQLRouteAPIAdapter.d.ts +24 -0
  11. package/dist/api/MySQLRouteAPIAdapter.js +311 -0
  12. package/dist/api/MySQLRouteAPIAdapter.js.map +1 -0
  13. package/dist/common/ReplicatedGTID.d.ts +59 -0
  14. package/dist/common/ReplicatedGTID.js +110 -0
  15. package/dist/common/ReplicatedGTID.js.map +1 -0
  16. package/dist/common/check-source-configuration.d.ts +3 -0
  17. package/dist/common/check-source-configuration.js +46 -0
  18. package/dist/common/check-source-configuration.js.map +1 -0
  19. package/dist/common/common-index.d.ts +6 -0
  20. package/dist/common/common-index.js +7 -0
  21. package/dist/common/common-index.js.map +1 -0
  22. package/dist/common/get-replication-columns.d.ts +12 -0
  23. package/dist/common/get-replication-columns.js +103 -0
  24. package/dist/common/get-replication-columns.js.map +1 -0
  25. package/dist/common/get-tables-from-pattern.d.ts +7 -0
  26. package/dist/common/get-tables-from-pattern.js +28 -0
  27. package/dist/common/get-tables-from-pattern.js.map +1 -0
  28. package/dist/common/mysql-to-sqlite.d.ts +4 -0
  29. package/dist/common/mysql-to-sqlite.js +56 -0
  30. package/dist/common/mysql-to-sqlite.js.map +1 -0
  31. package/dist/common/read-executed-gtid.d.ts +6 -0
  32. package/dist/common/read-executed-gtid.js +40 -0
  33. package/dist/common/read-executed-gtid.js.map +1 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.js +4 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/module/MySQLModule.d.ts +13 -0
  38. package/dist/module/MySQLModule.js +46 -0
  39. package/dist/module/MySQLModule.js.map +1 -0
  40. package/dist/replication/BinLogReplicationJob.d.ts +14 -0
  41. package/dist/replication/BinLogReplicationJob.js +88 -0
  42. package/dist/replication/BinLogReplicationJob.js.map +1 -0
  43. package/dist/replication/BinLogReplicator.d.ts +13 -0
  44. package/dist/replication/BinLogReplicator.js +25 -0
  45. package/dist/replication/BinLogReplicator.js.map +1 -0
  46. package/dist/replication/BinLogStream.d.ts +43 -0
  47. package/dist/replication/BinLogStream.js +421 -0
  48. package/dist/replication/BinLogStream.js.map +1 -0
  49. package/dist/replication/MySQLConnectionManager.d.ts +43 -0
  50. package/dist/replication/MySQLConnectionManager.js +81 -0
  51. package/dist/replication/MySQLConnectionManager.js.map +1 -0
  52. package/dist/replication/MySQLConnectionManagerFactory.d.ts +10 -0
  53. package/dist/replication/MySQLConnectionManagerFactory.js +21 -0
  54. package/dist/replication/MySQLConnectionManagerFactory.js.map +1 -0
  55. package/dist/replication/MySQLErrorRateLimiter.d.ts +10 -0
  56. package/dist/replication/MySQLErrorRateLimiter.js +43 -0
  57. package/dist/replication/MySQLErrorRateLimiter.js.map +1 -0
  58. package/dist/replication/zongji/zongji-utils.d.ts +7 -0
  59. package/dist/replication/zongji/zongji-utils.js +19 -0
  60. package/dist/replication/zongji/zongji-utils.js.map +1 -0
  61. package/dist/types/types.d.ts +50 -0
  62. package/dist/types/types.js +61 -0
  63. package/dist/types/types.js.map +1 -0
  64. package/dist/utils/mysql_utils.d.ts +14 -0
  65. package/dist/utils/mysql_utils.js +38 -0
  66. package/dist/utils/mysql_utils.js.map +1 -0
  67. package/package.json +51 -0
  68. package/src/api/MySQLRouteAPIAdapter.ts +357 -0
  69. package/src/common/ReplicatedGTID.ts +158 -0
  70. package/src/common/check-source-configuration.ts +59 -0
  71. package/src/common/common-index.ts +6 -0
  72. package/src/common/get-replication-columns.ts +124 -0
  73. package/src/common/get-tables-from-pattern.ts +44 -0
  74. package/src/common/mysql-to-sqlite.ts +59 -0
  75. package/src/common/read-executed-gtid.ts +43 -0
  76. package/src/index.ts +5 -0
  77. package/src/module/MySQLModule.ts +53 -0
  78. package/src/replication/BinLogReplicationJob.ts +97 -0
  79. package/src/replication/BinLogReplicator.ts +35 -0
  80. package/src/replication/BinLogStream.ts +547 -0
  81. package/src/replication/MySQLConnectionManager.ts +104 -0
  82. package/src/replication/MySQLConnectionManagerFactory.ts +28 -0
  83. package/src/replication/MySQLErrorRateLimiter.ts +44 -0
  84. package/src/replication/zongji/zongji-utils.ts +32 -0
  85. package/src/replication/zongji/zongji.d.ts +98 -0
  86. package/src/types/types.ts +102 -0
  87. package/src/utils/mysql_utils.ts +47 -0
  88. package/test/src/binlog_stream.test.ts +288 -0
  89. package/test/src/binlog_stream_utils.ts +152 -0
  90. package/test/src/env.ts +7 -0
  91. package/test/src/setup.ts +7 -0
  92. package/test/src/util.ts +62 -0
  93. package/test/tsconfig.json +28 -0
  94. package/tsconfig.json +26 -0
  95. package/tsconfig.tsbuildinfo +1 -0
  96. package/vitest.config.ts +15 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # @powersync/service-module-mysql
2
+
3
+ ## 0.0.0-dev-20241015210820
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [e4d19b2]
8
+ - Updated dependencies [d2ece1b]
9
+ - Updated dependencies [d2ece1b]
10
+ - Updated dependencies [9e78ff1]
11
+ - Updated dependencies [d2ece1b]
12
+ - Updated dependencies [1fd50a5]
13
+ - Updated dependencies [d51921f]
14
+ - Updated dependencies [4ecaee2]
15
+ - Updated dependencies [0e16938]
16
+ - Updated dependencies [aa4eb0a]
17
+ - @powersync/service-core@0.0.0-dev-20241015210820
18
+ - @powersync/lib-services-framework@0.0.0-dev-20241015210820
19
+ - @powersync/service-sync-rules@0.0.0-dev-20241015210820
20
+ - @powersync/service-types@0.0.0-dev-20241015210820
package/LICENSE ADDED
@@ -0,0 +1,67 @@
1
+ # Functional Source License, Version 1.1, Apache 2.0 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-Apache-2.0
6
+
7
+ ## Notice
8
+
9
+ Copyright 2023-2024 Journey Mobile, Inc.
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under these Terms and Conditions, as indicated by our inclusion of these Terms and Conditions with the Software.
20
+
21
+ ### License Grant
22
+
23
+ Subject to your compliance with this License Grant and the Patents, Redistribution and Trademark clauses below, we hereby grant you the right to use, copy, modify, create derivative works, publicly perform, publicly display and redistribute the Software for any Permitted Purpose identified below.
24
+
25
+ ### Permitted Purpose
26
+
27
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use means making the Software available to others in a commercial product or service that:
28
+
29
+ 1. substitutes for the Software;
30
+ 2. substitutes for any other product or service we offer using the Software that exists as of the date we make the Software available; or
31
+ 3. offers the same or substantially similar functionality as the Software.
32
+
33
+ Permitted Purposes specifically include using the Software:
34
+
35
+ 1. for your internal use and access;
36
+ 2. for non-commercial education;
37
+ 3. for non-commercial research; and
38
+ 4. in connection with professional services that you provide to a licensee using the Software in accordance with these Terms and Conditions.
39
+
40
+ ### Patents
41
+
42
+ To the extent your use for a Permitted Purpose would necessarily infringe our patents, the license grant above includes a license under our patents. If you make a claim against any party that the Software infringes or contributes to the infringement of any patent, then your patent license to the Software ends immediately.
43
+
44
+ ### Redistribution
45
+
46
+ The Terms and Conditions apply to all copies, modifications and derivatives of the Software.
47
+ If you redistribute any copies, modifications or derivatives of the Software, you must include a copy of or a link to these Terms and Conditions and not remove any copyright notices provided in or with the Software.
48
+
49
+ ### Disclaimer
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
52
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
53
+
54
+ ### Trademarks
55
+
56
+ Except for displaying the License Details and identifying us as the origin of the Software, you have no right under these Terms and Conditions to use our trademarks, trade names, service marks or product names.
57
+
58
+ ## Grant of Future License
59
+
60
+ We hereby irrevocably grant you an additional license to use the Software under the Apache License, Version 2.0 that is effective on the second anniversary of the date we make the Software available. On or after that date, you may use the Software under the Apache License, Version 2.0, in which case the following will apply:
61
+
62
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
63
+ You may obtain a copy of the License at
64
+
65
+ http://www.apache.org/licenses/LICENSE-2.0
66
+
67
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # PowerSync MySQL Module
2
+
3
+ This is a module which provides MySQL replication to PowerSync.
@@ -0,0 +1,2 @@
1
+ PS_MONGO_URI=mongodb://mongo:27017/powersync_demo
2
+ PS_PORT=8080
package/dev/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # MySQL Development Helpers
2
+
3
+ This folder contains some helpers for developing with MySQL.
4
+
5
+ - `./.env.template` contains basic settings to be applied to a root `.env` file
6
+ - `./config` contains YAML configuration files for a MySQL todo list application
7
+ - `./docker/mysql` contains a docker compose file for starting Mysql
8
+
9
+ TODO this does not contain any auth or backend functionality.
@@ -0,0 +1,12 @@
1
+ # See Documentation for more information:
2
+ # https://docs.powersync.com/usage/sync-rules
3
+ # Note that changes to this file are not watched.
4
+ # The service needs to be restarted for changes to take effect.
5
+
6
+ # Note that specifying the schema is currently required due to the default
7
+ # schema being specified as `public`, but in mysql the schema is the database name
8
+ bucket_definitions:
9
+ global:
10
+ data:
11
+ - SELECT * FROM mydatabase.lists
12
+ - SELECT * FROM mydatabase.todos
@@ -0,0 +1,17 @@
1
+ services:
2
+ mysql:
3
+ image: mysql:8.0
4
+ environment:
5
+ MYSQL_ROOT_PASSWORD: root_password
6
+ MYSQL_DATABASE: mydatabase
7
+ MYSQL_USER: myuser
8
+ MYSQL_PASSWORD: mypassword
9
+ ports:
10
+ - "3306:3306"
11
+ volumes:
12
+ - ./init-scripts/my.cnf:/etc/mysql/my.cnf
13
+ - ./init-scripts/mysql.sql:/docker-entrypoint-initdb.d/init_user.sql
14
+ - mysql_data:/var/lib/mysql
15
+
16
+ volumes:
17
+ mysql_data:
@@ -0,0 +1,9 @@
1
+ [mysqld]
2
+ gtid_mode = ON
3
+ enforce-gtid-consistency = ON
4
+ # Row format required for ZongJi
5
+ binlog_format = row
6
+ log_bin=mysql-bin
7
+ server-id=1
8
+ binlog-do-db=mydatabase
9
+ replicate-do-table=mydatabase.lists
@@ -0,0 +1,38 @@
1
+ -- Create a user with necessary privileges
2
+ CREATE USER 'repl_user'@'%' IDENTIFIED BY 'good_password';
3
+
4
+ -- Grant replication client privilege
5
+ GRANT REPLICATION SLAVE, REPLICATION CLIENT, RELOAD ON *.* TO 'repl_user'@'%';
6
+ GRANT REPLICATION SLAVE, REPLICATION CLIENT, RELOAD ON *.* TO 'myuser'@'%';
7
+
8
+ -- Grant access to the specific database
9
+ GRANT ALL PRIVILEGES ON mydatabase.* TO 'repl_user'@'%';
10
+
11
+ -- Apply changes
12
+ FLUSH PRIVILEGES;
13
+
14
+ CREATE TABLE lists (
15
+ id CHAR(36) NOT NULL DEFAULT (UUID()), -- String UUID (36 characters)
16
+ created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
17
+ name TEXT NOT NULL,
18
+ owner_id CHAR(36) NOT NULL,
19
+ PRIMARY KEY (id)
20
+ );
21
+
22
+ CREATE TABLE todos (
23
+ id CHAR(36) NOT NULL DEFAULT (UUID()), -- String UUID (36 characters)
24
+ created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
25
+ completed_at TIMESTAMP NULL,
26
+ description TEXT NOT NULL,
27
+ completed BOOLEAN NOT NULL DEFAULT FALSE,
28
+ created_by CHAR(36) NULL,
29
+ completed_by CHAR(36) NULL,
30
+ list_id CHAR(36) NOT NULL,
31
+ PRIMARY KEY (id),
32
+ FOREIGN KEY (list_id) REFERENCES lists (id) ON DELETE CASCADE
33
+ );
34
+
35
+ -- TODO fix case where no data is present
36
+ INSERT INTO lists (id, name, owner_id)
37
+ VALUES
38
+ (UUID(), 'Do a demo', UUID());
@@ -0,0 +1,24 @@
1
+ import { api, ParseSyncRulesOptions } from '@powersync/service-core';
2
+ import * as sync_rules from '@powersync/service-sync-rules';
3
+ import * as service_types from '@powersync/service-types';
4
+ import mysql from 'mysql2/promise';
5
+ import * as types from '../types/types.js';
6
+ export declare class MySQLRouteAPIAdapter implements api.RouteAPI {
7
+ protected config: types.ResolvedConnectionConfig;
8
+ protected pool: mysql.Pool;
9
+ constructor(config: types.ResolvedConnectionConfig);
10
+ shutdown(): Promise<void>;
11
+ getSourceConfig(): Promise<service_types.configFile.ResolvedDataSourceConfig>;
12
+ getParseSyncRulesOptions(): ParseSyncRulesOptions;
13
+ getConnectionStatus(): Promise<service_types.ConnectionStatusV2>;
14
+ executeQuery(query: string, params: any[]): Promise<service_types.internal_routes.ExecuteSqlResponse>;
15
+ getDebugTablesInfo(tablePatterns: sync_rules.TablePattern[], sqlSyncRules: sync_rules.SqlSyncRules): Promise<api.PatternResult[]>;
16
+ protected getDebugTableInfo(tablePattern: sync_rules.TablePattern, tableName: string, syncRules: sync_rules.SqlSyncRules): Promise<service_types.TableInfo>;
17
+ getReplicationLag(options: api.ReplicationLagOptions): Promise<number | undefined>;
18
+ getReplicationHead(): Promise<string>;
19
+ getConnectionSchema(): Promise<service_types.DatabaseSchema[]>;
20
+ protected retriedQuery(options: {
21
+ query: string;
22
+ params?: any[];
23
+ }): Promise<[mysql.RowDataPacket[], mysql.FieldPacket[]]>;
24
+ }
@@ -0,0 +1,311 @@
1
+ import { storage } from '@powersync/service-core';
2
+ import * as sync_rules from '@powersync/service-sync-rules';
3
+ import * as service_types from '@powersync/service-types';
4
+ import * as common from '../common/common-index.js';
5
+ import * as mysql_utils from '../utils/mysql_utils.js';
6
+ import { toExpressionTypeFromMySQLType } from '../common/common-index.js';
7
+ export class MySQLRouteAPIAdapter {
8
+ constructor(config) {
9
+ this.config = config;
10
+ this.pool = mysql_utils.createPool(config).promise();
11
+ }
12
+ async shutdown() {
13
+ return this.pool.end();
14
+ }
15
+ async getSourceConfig() {
16
+ return this.config;
17
+ }
18
+ getParseSyncRulesOptions() {
19
+ return {
20
+ // In MySQL Schema and Database are the same thing. There is no default database
21
+ defaultSchema: this.config.database
22
+ };
23
+ }
24
+ async getConnectionStatus() {
25
+ const base = {
26
+ id: this.config.id,
27
+ uri: `mysql://${this.config.hostname}:${this.config.port}/${this.config.database}`
28
+ };
29
+ try {
30
+ await this.retriedQuery({
31
+ query: `SELECT 'PowerSync connection test'`
32
+ });
33
+ }
34
+ catch (e) {
35
+ return {
36
+ ...base,
37
+ connected: false,
38
+ errors: [{ level: 'fatal', message: `${e.code} - message: ${e.message}` }]
39
+ };
40
+ }
41
+ const connection = await this.pool.getConnection();
42
+ try {
43
+ const errors = await common.checkSourceConfiguration(connection);
44
+ if (errors.length) {
45
+ return {
46
+ ...base,
47
+ connected: true,
48
+ errors: errors.map((e) => ({ level: 'fatal', message: e }))
49
+ };
50
+ }
51
+ }
52
+ catch (e) {
53
+ return {
54
+ ...base,
55
+ connected: true,
56
+ errors: [{ level: 'fatal', message: e.message }]
57
+ };
58
+ }
59
+ finally {
60
+ connection.release();
61
+ }
62
+ return {
63
+ ...base,
64
+ connected: true,
65
+ errors: []
66
+ };
67
+ }
68
+ async executeQuery(query, params) {
69
+ if (!this.config.debug_api) {
70
+ return service_types.internal_routes.ExecuteSqlResponse.encode({
71
+ results: {
72
+ columns: [],
73
+ rows: []
74
+ },
75
+ success: false,
76
+ error: 'SQL querying is not enabled'
77
+ });
78
+ }
79
+ try {
80
+ const [results, fields] = await this.pool.query(query, params);
81
+ return service_types.internal_routes.ExecuteSqlResponse.encode({
82
+ success: true,
83
+ results: {
84
+ columns: fields.map((c) => c.name),
85
+ rows: results.map((row) => {
86
+ /**
87
+ * Row will be in the format:
88
+ * @rows: [ { test: 2 } ]
89
+ */
90
+ return fields.map((c) => {
91
+ const value = row[c.name];
92
+ const sqlValue = sync_rules.toSyncRulesValue(value);
93
+ if (typeof sqlValue == 'bigint') {
94
+ return Number(value);
95
+ }
96
+ else if (value instanceof Date) {
97
+ return value.toISOString();
98
+ }
99
+ else if (sync_rules.isJsonValue(sqlValue)) {
100
+ return sqlValue;
101
+ }
102
+ else {
103
+ return null;
104
+ }
105
+ });
106
+ })
107
+ }
108
+ });
109
+ }
110
+ catch (e) {
111
+ return service_types.internal_routes.ExecuteSqlResponse.encode({
112
+ results: {
113
+ columns: [],
114
+ rows: []
115
+ },
116
+ success: false,
117
+ error: e.message
118
+ });
119
+ }
120
+ }
121
+ async getDebugTablesInfo(tablePatterns, sqlSyncRules) {
122
+ let result = [];
123
+ for (let tablePattern of tablePatterns) {
124
+ const schema = tablePattern.schema;
125
+ let patternResult = {
126
+ schema: schema,
127
+ pattern: tablePattern.tablePattern,
128
+ wildcard: tablePattern.isWildcard
129
+ };
130
+ result.push(patternResult);
131
+ if (tablePattern.isWildcard) {
132
+ patternResult.tables = [];
133
+ const prefix = tablePattern.tablePrefix;
134
+ const [results] = await this.pool.query(`SELECT
135
+ TABLE_NAME AS table_name
136
+ FROM
137
+ INFORMATION_SCHEMA.TABLES
138
+ WHERE
139
+ TABLE_SCHEMA = ?
140
+ AND TABLE_NAME LIKE ?`, [schema, tablePattern.tablePattern]);
141
+ for (let row of results) {
142
+ const name = row.table_name;
143
+ if (!name.startsWith(prefix)) {
144
+ continue;
145
+ }
146
+ const details = await this.getDebugTableInfo(tablePattern, name, sqlSyncRules);
147
+ patternResult.tables.push(details);
148
+ }
149
+ }
150
+ else {
151
+ const [results] = await this.pool.query(`SELECT
152
+ TABLE_NAME AS table_name
153
+ FROM
154
+ INFORMATION_SCHEMA.TABLES
155
+ WHERE
156
+ TABLE_SCHEMA = ?
157
+ AND TABLE_NAME = ?`, [tablePattern.schema, tablePattern.tablePattern]);
158
+ if (results.length == 0) {
159
+ // Table not found
160
+ patternResult.table = await this.getDebugTableInfo(tablePattern, tablePattern.name, sqlSyncRules);
161
+ }
162
+ else {
163
+ const row = results[0];
164
+ patternResult.table = await this.getDebugTableInfo(tablePattern, row.table_name, sqlSyncRules);
165
+ }
166
+ }
167
+ }
168
+ return result;
169
+ }
170
+ async getDebugTableInfo(tablePattern, tableName, syncRules) {
171
+ const { schema } = tablePattern;
172
+ let idColumnsResult = null;
173
+ let idColumnsError = null;
174
+ let connection = null;
175
+ try {
176
+ connection = await this.pool.getConnection();
177
+ idColumnsResult = await common.getReplicationIdentityColumns({
178
+ connection: connection,
179
+ schema,
180
+ table_name: tableName
181
+ });
182
+ }
183
+ catch (ex) {
184
+ idColumnsError = { level: 'fatal', message: ex.message };
185
+ }
186
+ finally {
187
+ connection?.release();
188
+ }
189
+ const idColumns = idColumnsResult?.columns ?? [];
190
+ const sourceTable = new storage.SourceTable(0, this.config.tag, tableName, schema, tableName, idColumns, true);
191
+ const syncData = syncRules.tableSyncsData(sourceTable);
192
+ const syncParameters = syncRules.tableSyncsParameters(sourceTable);
193
+ if (idColumns.length == 0 && idColumnsError == null) {
194
+ let message = `No replication id found for ${sourceTable.qualifiedName}. Replica identity: ${idColumnsResult?.identity}.`;
195
+ if (idColumnsResult?.identity == 'default') {
196
+ message += ' Configure a primary key on the table.';
197
+ }
198
+ idColumnsError = { level: 'fatal', message };
199
+ }
200
+ let selectError = null;
201
+ try {
202
+ await this.retriedQuery({
203
+ query: `SELECT * FROM ${sourceTable.table} LIMIT 1`
204
+ });
205
+ }
206
+ catch (e) {
207
+ selectError = { level: 'fatal', message: e.message };
208
+ }
209
+ return {
210
+ schema: schema,
211
+ name: tableName,
212
+ pattern: tablePattern.isWildcard ? tablePattern.tablePattern : undefined,
213
+ replication_id: idColumns.map((c) => c.name),
214
+ data_queries: syncData,
215
+ parameter_queries: syncParameters,
216
+ errors: [idColumnsError, selectError].filter((error) => error != null)
217
+ };
218
+ }
219
+ async getReplicationLag(options) {
220
+ const { bucketStorage } = options;
221
+ const lastCheckpoint = await bucketStorage.getCheckpoint();
222
+ const current = lastCheckpoint.lsn
223
+ ? common.ReplicatedGTID.fromSerialized(lastCheckpoint.lsn)
224
+ : common.ReplicatedGTID.ZERO;
225
+ const connection = await this.pool.getConnection();
226
+ const head = await common.readExecutedGtid(connection);
227
+ const lag = await current.distanceTo(connection, head);
228
+ connection.release();
229
+ if (lag == null) {
230
+ throw new Error(`Could not determine replication lag`);
231
+ }
232
+ return lag;
233
+ }
234
+ async getReplicationHead() {
235
+ const connection = await this.pool.getConnection();
236
+ const result = await common.readExecutedGtid(connection);
237
+ connection.release();
238
+ return result.comparable;
239
+ }
240
+ async getConnectionSchema() {
241
+ const [results] = await this.retriedQuery({
242
+ query: `
243
+ SELECT
244
+ tbl.schema_name,
245
+ tbl.table_name,
246
+ tbl.quoted_name,
247
+ JSON_ARRAYAGG(JSON_OBJECT('column_name', a.column_name, 'data_type', a.data_type)) AS columns
248
+ FROM
249
+ (
250
+ SELECT
251
+ TABLE_SCHEMA AS schema_name,
252
+ TABLE_NAME AS table_name,
253
+ CONCAT('\`', TABLE_SCHEMA, '\`.\`', TABLE_NAME, '\`') AS quoted_name
254
+ FROM
255
+ INFORMATION_SCHEMA.TABLES
256
+ WHERE
257
+ TABLE_TYPE = 'BASE TABLE'
258
+ AND TABLE_SCHEMA NOT IN ('information_schema', 'mysql', 'performance_schema', 'sys')
259
+ ) AS tbl
260
+ LEFT JOIN
261
+ (
262
+ SELECT
263
+ TABLE_SCHEMA AS schema_name,
264
+ TABLE_NAME AS table_name,
265
+ COLUMN_NAME AS column_name,
266
+ COLUMN_TYPE AS data_type
267
+ FROM
268
+ INFORMATION_SCHEMA.COLUMNS
269
+ ) AS a
270
+ ON
271
+ tbl.schema_name = a.schema_name
272
+ AND tbl.table_name = a.table_name
273
+ GROUP BY
274
+ tbl.schema_name, tbl.table_name, tbl.quoted_name;
275
+ `
276
+ });
277
+ /**
278
+ * Reduces the SQL results into a Record of {@link DatabaseSchema}
279
+ * then returns the values as an array.
280
+ */
281
+ return Object.values(results.reduce((hash, result) => {
282
+ const schema = hash[result.schema_name] ||
283
+ (hash[result.schema_name] = {
284
+ name: result.schema_name,
285
+ tables: []
286
+ });
287
+ schema.tables.push({
288
+ name: result.table_name,
289
+ columns: result.columns.map((column) => ({
290
+ name: column.column_name,
291
+ type: column.data_type,
292
+ sqlite_type: toExpressionTypeFromMySQLType(column.data_type).typeFlags,
293
+ internal_type: column.data_type,
294
+ pg_type: column.data_type
295
+ }))
296
+ });
297
+ return hash;
298
+ }, {}));
299
+ }
300
+ async retriedQuery(options) {
301
+ const connection = await this.pool.getConnection();
302
+ return mysql_utils
303
+ .retriedQuery({
304
+ connection: connection,
305
+ query: options.query,
306
+ params: options.params
307
+ })
308
+ .finally(() => connection.release());
309
+ }
310
+ }
311
+ //# sourceMappingURL=MySQLRouteAPIAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MySQLRouteAPIAdapter.js","sourceRoot":"","sources":["../../src/api/MySQLRouteAPIAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAE9E,OAAO,KAAK,UAAU,MAAM,+BAA+B,CAAC;AAC5D,OAAO,KAAK,aAAa,MAAM,0BAA0B,CAAC;AAE1D,OAAO,KAAK,MAAM,MAAM,2BAA2B,CA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AC,MAAM,CAAC,CAAC,IAAkD,EAAE,MAAM,EAAE,EAAE;YAChG,MAAM,MAAM,GACV,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;gBACxB,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG;oBAC1B,IAAI,EAAE,MAAM,CAAC,WAAW;oBACxB,MAAM,EAAE,EAAE;iBACX,CAAC,CAAC;YAEL,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;gBACjB,IAAI,EAAE,MAAM,CAAC,UAAU;gBACvB,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;oBACvC,IAAI,EAAE,MAAM,CAAC,WAAW;oBACxB,IAAI,EAAE,MAAM,CAAC,SAAS;oBACtB,WAAW,EAAE,6BAA6B,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,SAAS;oBACtE,aAAa,EAAE,MAAM,CAAC,SAAS;oBAC/B,OAAO,EAAE,MAAM,CAAC,SAAS;iBAC1B,CAAC,CAAC;aACJ,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;QACd,CAAC,EAAE,EAAE,CAAC,CACP,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,OAA0C;QACrE,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QAEnD,OAAO,WAAW;aACf,YAAY,CAAC;YACZ,UAAU,EAAE,UAAU;YACtB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC;aACD,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;IACzC,CAAC;CACF"}
@@ -0,0 +1,59 @@
1
+ import mysql from 'mysql2/promise';
2
+ export type BinLogPosition = {
3
+ filename: string;
4
+ offset: number;
5
+ };
6
+ export type ReplicatedGTIDSpecification = {
7
+ raw_gtid: string;
8
+ /**
9
+ * The (end) position in a BinLog file where this transaction has been replicated in.
10
+ */
11
+ position: BinLogPosition;
12
+ };
13
+ export type BinLogGTIDFormat = {
14
+ server_id: Buffer;
15
+ transaction_range: number;
16
+ };
17
+ export type BinLogGTIDEvent = {
18
+ raw_gtid: BinLogGTIDFormat;
19
+ position: BinLogPosition;
20
+ };
21
+ /**
22
+ * A wrapper around the MySQL GTID value.
23
+ * This adds and tracks additional metadata such as the BinLog filename
24
+ * and position where this GTID could be located.
25
+ */
26
+ export declare class ReplicatedGTID {
27
+ protected options: ReplicatedGTIDSpecification;
28
+ static fromSerialized(comparable: string): ReplicatedGTID;
29
+ private static deserialize;
30
+ static fromBinLogEvent(event: BinLogGTIDEvent): ReplicatedGTID;
31
+ /**
32
+ * Special case for the zero GTID which means no transactions have been executed.
33
+ */
34
+ static ZERO: ReplicatedGTID;
35
+ constructor(options: ReplicatedGTIDSpecification);
36
+ /**
37
+ * Get the BinLog position of this replicated GTID event
38
+ */
39
+ get position(): BinLogPosition;
40
+ /**
41
+ * Get the raw Global Transaction ID. This of the format `server_id:transaction_ranges`
42
+ */
43
+ get raw(): string;
44
+ get serverId(): string;
45
+ /**
46
+ * Transforms a GTID into a comparable string format, ensuring lexicographical
47
+ * order aligns with the GTID's relative age. This assumes that all GTIDs
48
+ * have the same server ID.
49
+ *
50
+ * @returns A comparable string in the format
51
+ * `padded_end_transaction|raw_gtid|binlog_filename|binlog_position`
52
+ */
53
+ get comparable(): string;
54
+ toString(): string;
55
+ /**
56
+ * Calculates the distance in bytes from this GTID to the provided argument.
57
+ */
58
+ distanceTo(connection: mysql.Connection, to: ReplicatedGTID): Promise<number | null>;
59
+ }