Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@oclif/plugin-commands": "^4.1.40",
"@oclif/plugin-help": "^6",
"@oclif/plugin-plugins": "^5",
"@powersync-community/sync-config-rewriter": "^0.1.4",
"@powersync/sync-config-tools": "^0.1.1",
"@powersync/cli-core": "workspace:*",
"@powersync/cli-plugin-config-edit": "workspace:*",
"@powersync/cli-plugin-docker": "workspace:*",
Expand Down
6 changes: 2 additions & 4 deletions cli/src/commands/migrate/sync-rules.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Flags, ux } from '@oclif/core';
import { instantiate } from '@powersync-community/sync-config-rewriter';
import { SharedInstanceCommand, SYNC_FILENAME, YAML_SYNC_RULES_SCHEMA } from '@powersync/cli-core';
import { instantiate } from '@powersync/sync-config-tools';
import { access, readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -37,9 +37,7 @@ export default class MigrateSyncRules extends SharedInstanceCommand {

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

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

const SyncStreamsRewriter = await instantiate(wasmBuffer);

Expand Down
44 changes: 44 additions & 0 deletions cli/test/commands/migrate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { runCommand } from '@oclif/test';
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { expect, onTestFinished, test } from 'vitest';

import { root } from '../helpers/root.js';

test('migrates from sync rules to sync streams', async () => {
const testDirectory = mkdtempSync(join(tmpdir(), 'migrate-test-'));
onTestFinished(() => rmSync(testDirectory, { recursive: true }));

const inputFile = join(testDirectory, 'input.yaml');
const outputFile = join(testDirectory, 'output.yaml');
writeFileSync(
inputFile,
`
bucket_definitions:
user_lists:
parameters: SELECT request.user_id() as user_id
data:
- SELECT * FROM lists WHERE owner_id = bucket.user_id
`
);

const result = await runCommand(`migrate sync-rules --input-file ${inputFile} --output-file ${outputFile}`, { root });
expect(result.error).toBeUndefined();

const transformed = readFileSync(outputFile).toString('utf-8');
expect(transformed)
.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.
# yaml-language-server: $schema=https://unpkg.com/@powersync/service-sync-rules@latest/schema/sync_rules.json
config:
edition: 3
streams:
# This Sync Stream has been translated from bucket definitions. There may be more efficient ways to express these queries.
# You can add additional queries to this list if you need them.
# For details, see the documentation: https://docs.powersync.com/sync/streams/overview
migrated_to_streams:
auto_subscribe: true
queries:
- SELECT * FROM lists WHERE owner_id = auth.user_id()
`);
});
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading