Skip to content

Commit ba74f4f

Browse files
committed
init
1 parent 800609b commit ba74f4f

10 files changed

Lines changed: 346 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Deploy Sync Rules
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "sync-rules.yaml"
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version-file: node/.nvmrc
25+
26+
- name: Install PowerSync CLI
27+
run: npm install -g @powersync/cli
28+
29+
- name: Deploy sync rules
30+
env:
31+
AUTH_TOKEN: ${{ secrets.POWERSYNC_AUTH_TOKEN }}
32+
INSTANCE_ID: ${{ secrets.POWERSYNC_INSTANCE_ID }}
33+
run: |
34+
npx powersync instance sync-rules deploy --filePath ./sync-rules.yaml -s
35+

.gitignore

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Dependencies
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
pnpm-debug.log*
7+
8+
# Environment variables
9+
.env
10+
.env.local
11+
.env.*.local
12+
13+
# But keep template files
14+
!.env.template
15+
!.env.example
16+
17+
# Build output
18+
dist/
19+
build/
20+
out/
21+
*.tsbuildinfo
22+
23+
# IDE & Editor files
24+
.vscode/
25+
.idea/
26+
*.swp
27+
*.swo
28+
*~
29+
.DS_Store
30+
31+
# Testing
32+
coverage/
33+
*.lcov
34+
.nyc_output/
35+
36+
# Logs
37+
logs/
38+
*.log
39+
40+
# Temporary files
41+
*.tmp
42+
.cache/
43+
.temp/
44+
45+
# Optional npm cache directory
46+
.npm
47+
48+
# Optional eslint cache
49+
.eslintcache
50+
51+
# TypeScript cache
52+
*.tsbuildinfo
53+
54+
# SQLite database
55+
*.sqlite

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## GitHub Actions Sync Rules Demo
2+
3+
This repository shows how to deploy PowerSync sync rules to an instance whenever a push to the `main` branch includes changes to `sync-rules.yaml`. The included GitHub Actions workflow installs the PowerSync CLI and runs the deployment command automatically.
4+
5+
## Prerequisites
6+
7+
- A PowerSync instance.
8+
- GitHub repository secrets named `POWERSYNC_AUTH_TOKEN` and `POWERSYNC_INSTANCE_ID`.
9+
10+
## Getting the Auth Token
11+
12+
1. Sign in to the PowerSync dashboard.
13+
2. Generate a personal access token with permissions to deploy sync rules.
14+
3. Store the token in your repository secrets as `POWERSYNC_AUTH_TOKEN`.
15+
4. Copy your PowerSync instance ID from the dashboard and store it as `POWERSYNC_INSTANCE_ID`.
16+
17+
With the token and instance ID in place, the workflow will authenticate and deploy your sync rules whenever the `sync-rules.yaml` file changes on the `main` branch.
18+
19+
## Node Sample
20+
21+
The `node/` directory contains a simple Node project that connects to PowerSync, runs `SELECT * FROM lists` and `SELECT * FROM todos`, and logs the results. It exists purely as a demo alongside the GitHub Actions workflow.
22+

node/.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
POWERSYNC_URL=http://localhost:8080
2+
BACKEND_URL=http://localhost:6060

node/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.16.0

node/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "js",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"dev": "node --experimental-strip-types src/index.ts",
9+
"update-sync-rules": "node --experimental-strip-types update-sync-rules.ts"
10+
},
11+
"keywords": [],
12+
"author": "",
13+
"license": "ISC",
14+
"dependencies": {
15+
"@powersync/node": "^0.10.1"
16+
},
17+
"devDependencies": {
18+
"@types/node": "^24.10.1",
19+
"dotenv": "^17.1.0"
20+
},
21+
"packageManager": "pnpm@10.12.1+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac"
22+
}

node/pnpm-lock.yaml

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

node/pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
onlyBuiltDependencies:
2+
- '@powersync/better-sqlite3'
3+
- '@powersync/node'

node/src/index.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import 'dotenv/config'
2+
import {
3+
column,
4+
Schema,
5+
Table,
6+
PowerSyncDatabase,
7+
} from "@powersync/node";
8+
9+
export class Connector {
10+
async fetchCredentials() {
11+
const endpoint = process.env.POWERSYNC_URL;
12+
if (!endpoint) {
13+
return null;
14+
}
15+
const token = await fetch(`${process.env.BACKEND_URL}/api/auth/token`)
16+
.then((response) => response.json())
17+
.then((data) => data.token as string);
18+
return { endpoint, token };
19+
}
20+
async uploadData(database: any) { }
21+
};
22+
23+
24+
const schema = new Schema({
25+
lists: new Table({
26+
name: column.text,
27+
created_at: column.text,
28+
owner_id: column.text,
29+
}),
30+
todos: new Table({
31+
description: column.text,
32+
list_id: column.text,
33+
completed: column.integer,
34+
}),
35+
});
36+
37+
const powerSync = new PowerSyncDatabase({
38+
schema,
39+
database: { dbFilename: "example.sqlite" },
40+
});
41+
42+
await powerSync.connect(new Connector(), {
43+
params: {
44+
test: "value"
45+
}
46+
});
47+
await powerSync.init();
48+
await powerSync.waitForFirstSync();
49+
50+
51+
const lists = await powerSync.getAll(`SELECT * FROM lists`);
52+
console.log("lists: ", lists);
53+
54+
const todos = await powerSync.getAll(`SELECT * FROM todos`);
55+
console.log("todos: ", todos);
56+
57+
await powerSync.disconnect();
58+
console.log("Disconnected and cleared the database.");
59+
60+
process.exit(0);

sync-rules.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bucket_definitions:
2+
global:
3+
data:
4+
- SELECT * FROM lists
5+
- SELECT * FROM todos

0 commit comments

Comments
 (0)