Skip to content

Commit 03d1e4a

Browse files
committed
Migrate command: Use sync-config-tools package
1 parent 1a4fa81 commit 03d1e4a

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@oclif/plugin-commands": "^4.1.40",
1717
"@oclif/plugin-help": "^6",
1818
"@oclif/plugin-plugins": "^5",
19-
"@powersync-community/sync-config-rewriter": "^0.1.4",
19+
"@powersync/sync-config-tools": "^0.1.1",
2020
"@powersync/cli-core": "workspace:*",
2121
"@powersync/cli-plugin-config-edit": "workspace:*",
2222
"@powersync/cli-plugin-docker": "workspace:*",

cli/src/commands/migrate/sync-rules.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Flags, ux } from '@oclif/core';
2-
import { instantiate } from '@powersync-community/sync-config-rewriter';
32
import { SharedInstanceCommand, SYNC_FILENAME, YAML_SYNC_RULES_SCHEMA } from '@powersync/cli-core';
3+
import { instantiate } from '@powersync/sync-config-tools';
44
import { access, readFile, writeFile } from 'node:fs/promises';
55
import { join } from 'node:path';
66
import { fileURLToPath } from 'node:url';
@@ -37,9 +37,7 @@ export default class MigrateSyncRules extends SharedInstanceCommand {
3737

3838
const syncInputContent = await readFile(syncInputPath, 'utf8');
3939

40-
const wasmBuffer = await readFile(
41-
fileURLToPath(import.meta.resolve('@powersync-community/sync-config-rewriter/compiled.wasm'))
42-
);
40+
const wasmBuffer = await readFile(fileURLToPath(import.meta.resolve('@powersync/sync-config-tools/compiled.wasm')));
4341

4442
const SyncStreamsRewriter = await instantiate(wasmBuffer);
4543

cli/test/commands/migrate.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { runCommand } from '@oclif/test';
2+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3+
import { tmpdir } from 'node:os';
4+
import { join } from 'node:path';
5+
import { expect, onTestFinished, test } from 'vitest';
6+
7+
import { root } from '../helpers/root.js';
8+
9+
test('migrates from sync rules to sync streams', async () => {
10+
const testDirectory = mkdtempSync(join(tmpdir(), 'migrate-test-'));
11+
onTestFinished(() => rmSync(testDirectory, { recursive: true }));
12+
13+
const inputFile = join(testDirectory, 'input.yaml');
14+
const outputFile = join(testDirectory, 'output.yaml');
15+
writeFileSync(
16+
inputFile,
17+
`
18+
bucket_definitions:
19+
user_lists:
20+
parameters: SELECT request.user_id() as user_id
21+
data:
22+
- SELECT * FROM lists WHERE owner_id = bucket.user_id
23+
`
24+
);
25+
26+
const result = await runCommand(`migrate sync-rules --input-file ${inputFile} --output-file ${outputFile}`, { root });
27+
expect(result.error).toBeUndefined();
28+
29+
const transformed = readFileSync(outputFile).toString('utf-8');
30+
expect(transformed)
31+
.toStrictEqual(`# Adds YAML Schema support for VSCode users with the YAML extension installed. This enables features like validation and autocompletion based on the provided schema.
32+
# yaml-language-server: $schema=https://unpkg.com/@powersync/service-sync-rules@latest/schema/sync_rules.json
33+
config:
34+
edition: 3
35+
streams:
36+
# This Sync Stream has been translated from bucket definitions. There may be more efficient ways to express these queries.
37+
# You can add additional queries to this list if you need them.
38+
# For details, see the documentation: https://docs.powersync.com/sync/streams/overview
39+
migrated_to_streams:
40+
auto_subscribe: true
41+
queries:
42+
- SELECT * FROM lists WHERE owner_id = auth.user_id()
43+
`);
44+
});

pnpm-lock.yaml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)