-
Notifications
You must be signed in to change notification settings - Fork 14
Postgres Bucket Storage Demo #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fd815d4
test config
stevensJourney 5407ece
postgres bucket storage demo
stevensJourney 3830bb0
Merge remote-tracking branch 'origin/main' into pg-storage
stevensJourney 1e47180
readme update
stevensJourney e883863
update environment
stevensJourney 4c29fb7
update image
stevensJourney a808367
use prod image
stevensJourney bf55090
fix container URL
kobiebotha 2eb6b7c
added batch limits config
stevensJourney f66898f
update demos
stevensJourney 3fa02b0
update readme
stevensJourney f7508df
development image
stevensJourney 02f93ff
update image
stevensJourney 1d863fd
use latest image
stevensJourney 99b1063
revert test
stevensJourney 8946a8e
Update services/powersync.yaml
stevensJourney 57a08d2
Update README.md
stevensJourney 07b9efd
use latest image
stevensJourney 85d4823
Merge branch 'pg-storage' of github.com:powersync-ja/self-host-test i…
stevensJourney 2a4f694
update image
stevensJourney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,8 @@ The `.env` file contains default configuration for the services. Reference this | |
| Ensure you have authenticated with our Docker Image repository. Please reach out to support for an access token. | ||
|
|
||
| ```bash | ||
| docker login [email protected] -u user | ||
| # the value for user doesn't matter | ||
| docker login container-registry.journeyapps.com -u user | ||
| ``` | ||
|
|
||
| This demo can be started by running the following in this demo directory | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # ==================== Postgres credentials ================================ | ||
| PG_DATABASE_NAME=postgres | ||
| PG_DATABASE_PORT=5432 | ||
| PG_DATABASE_USER=postgres | ||
| PG_DATABASE_PASSWORD=postgres | ||
| PS_DATA_SOURCE_URI=postgres://${PG_DATABASE_USER}:${PG_DATABASE_PASSWORD}@pg-db:${PG_DATABASE_PORT}/${PG_DATABASE_NAME} | ||
|
|
||
|
|
||
| PG_STORAGE_DATABASE_NAME=postgres | ||
| PG_STORAGE_DATABASE_PORT=5431 | ||
| PG_STORAGE_DATABASE_USER=postgres | ||
| PG_STORAGE_DATABASE_PASSWORD=postgres | ||
| PS_STORAGE_SOURCE_URI=postgres://${PG_STORAGE_DATABASE_USER}:${PG_STORAGE_DATABASE_PASSWORD}@pg-storage:${PG_STORAGE_DATABASE_PORT}/${PG_STORAGE_DATABASE_NAME} | ||
|
|
||
| # ==================== Demo config ========================================= | ||
| DEMO_BACKEND_PORT=6060 | ||
| DEMO_BACKEND_DATABASE_TYPE=postgres | ||
| DEMO_BACKEND_DATABASE_URI=postgres://${PG_DATABASE_USER}:${PG_DATABASE_PASSWORD}@pg-db:${PG_DATABASE_PORT}/${PG_DATABASE_NAME} | ||
| # The front-end demo application is accessible at this port on the host machine | ||
| DEMO_CLIENT_PORT=3039 | ||
| PS_JWKS_URL=http://demo-backend:${DEMO_BACKEND_PORT}/api/auth/keys | ||
|
|
||
| # These can be generated by following the instructions in the `key-generator` folder | ||
| # A temporary key will be used if these are not specified | ||
| DEMO_JWKS_PUBLIC_KEY= | ||
| DEMO_JWKS_PRIVATE_KEY= | ||
|
|
||
| # ==================== PowerSync variables ==================== | ||
| # The PowerSync API is accessible via this port | ||
| PS_PORT=8080 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # JavaScript PowerSync + Postgres Bucket Storage | ||
|
|
||
| This is a demo for using Postgres as the sync bucket storage driver with PowerSync. | ||
|
|
||
| Separate Postgres servers are required for the bucket storage and replication data source. | ||
|
|
||
| ## Running | ||
|
|
||
| The `.env` file contains default configuration for the services. Reference this to connect to any services locally. | ||
|
|
||
| This demo can be started by running the following in this demo directory | ||
|
|
||
| ```bash | ||
| docker compose up | ||
| ``` | ||
|
|
||
| or in the root directory run | ||
|
|
||
| ```bash | ||
| docker compose -f demos/nodejs-postgres-bucket-storage/docker-compose.yaml up | ||
| ``` | ||
|
|
||
| The frontend can be accessed at `http://localhost:3039` in a browser. | ||
|
|
||
| The Postgres databases can be accessed at the following URIs | ||
|
|
||
| Application data: `postgres://postgres:postgres@localhost:5432/postgres` | ||
|
|
||
| bucket storage: `postgres://postgres:postgres@localhost:5431/postgres` | ||
| Bucket storage tables are located in the `powersync` schema. |
68 changes: 68 additions & 0 deletions
68
demos/nodejs-postgres-bucket-storage/config/powersync.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # yaml-language-server: $schema=../schema/schema.json | ||
|
|
||
| # Note that this example uses YAML custom tags for environment variable substitution. | ||
| # Using `!env [variable name]` will substitute the value of the environment variable named | ||
| # [variable name]. | ||
| # | ||
| # Only environment variables with names starting with `PS_` can be substituted. | ||
| # | ||
| # e.g. With the environment variable `export PS_MONGO_URI=mongodb://localhost:27017` | ||
| # and YAML code: | ||
| # uri: !env PS_MONGO_URI | ||
| # The YAML will resolve to: | ||
| # uri: mongodb://localhost:27017 | ||
| # | ||
| # If using VS Code see the `.vscode/settings.json` definitions which define custom tags. | ||
|
|
||
| # migrations: | ||
| # # Migrations run automatically by default. | ||
| # # Setting this to true will skip automatic migrations. | ||
| # # Migrations can be triggered externally by altering the container `command`. | ||
| # disable_auto_migration: true | ||
|
|
||
| # Settings for telemetry reporting | ||
| # See https://docs.powersync.com/self-hosting/telemetry | ||
| telemetry: | ||
| # Opt out of reporting anonymized usage metrics to PowerSync telemetry service | ||
| disable_telemetry_sharing: false | ||
|
|
||
| # Settings for source database replication | ||
| replication: | ||
| # Specify database connection details | ||
| # Note only 1 connection is currently supported | ||
| # Multiple connection support is on the roadmap | ||
| connections: | ||
| - type: postgresql | ||
| # The PowerSync server container can access the Postgres DB via the DB's service name. | ||
| # In this case the hostname is pg-db | ||
|
|
||
| uri: !env PS_DATA_SOURCE_URI | ||
| # SSL settings | ||
| sslmode: disable # 'verify-full' (default) or 'verify-ca' or 'disable' | ||
|
|
||
| # Connection settings for sync bucket storage | ||
| storage: | ||
| type: postgresql | ||
| # This accepts the same parameters as a postgres data source connection | ||
| uri: !env PS_STORAGE_SOURCE_URI | ||
| sslmode: disable # 'verify-full' (default) or 'verify-ca' or 'disable' | ||
|
|
||
| # The port which the PowerSync API server will listen on | ||
| port: !env PS_PORT | ||
|
|
||
| # Specify sync rules | ||
| sync_rules: | ||
| path: sync_rules.yaml | ||
|
|
||
| # Client (application end user) authentication settings | ||
| client_auth: | ||
| # JWKS URIs can be specified here | ||
| jwks_uri: !env PS_JWKS_URL | ||
|
|
||
| # JWKS audience | ||
| audience: ["powersync-dev", "powersync"] | ||
|
|
||
| api: | ||
| tokens: | ||
| # These tokens are used for local admin API route authentication | ||
| - use_a_better_token_in_production |
13 changes: 13 additions & 0 deletions
13
demos/nodejs-postgres-bucket-storage/config/sync_rules.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # yaml-language-server: $schema=https://unpkg.com/@powersync/service-sync-rules@latest/schema/sync_rules.json | ||
| # | ||
| # See Documentation for more information: | ||
| # https://docs.powersync.com/usage/sync-rules | ||
| # | ||
| # Note that changes to this file are not watched. | ||
| # The service needs to be restarted for changes to take effect. | ||
|
|
||
| bucket_definitions: | ||
| global: | ||
| data: | ||
| - SELECT * FROM lists | ||
| - SELECT * FROM todos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # Include syntax requires Docker compose > 2.20.3 | ||
| # https://docs.docker.com/compose/release-notes/#2203 | ||
| include: | ||
| # Demo NodeJS backend server and front-end web client | ||
| - path: ../nodejs/ps-nodejs-demo.yaml | ||
|
|
||
| services: | ||
| # Extend PowerSync with Mongo and Postgres healthchecks | ||
| powersync: | ||
| extends: | ||
| file: ../../services/powersync.yaml | ||
| service: powersync | ||
| depends_on: | ||
| pg-db: | ||
| condition: service_healthy | ||
| pg-storage: | ||
| condition: service_healthy | ||
| volumes: | ||
| - ./config:/config | ||
| environment: | ||
| PS_STORAGE_SOURCE_URI: ${PS_STORAGE_SOURCE_URI} | ||
| pg-db: | ||
| extends: | ||
| file: ../../services/postgres.yaml | ||
| service: pg-db | ||
| volumes: | ||
| - ../nodejs/init-scripts:/docker-entrypoint-initdb.d | ||
|
|
||
| pg-storage: | ||
| image: postgres:latest | ||
| restart: always | ||
| environment: | ||
| - POSTGRES_USER=${PG_STORAGE_DATABASE_USER} | ||
| - POSTGRES_DB=${PG_STORAGE_DATABASE_NAME} | ||
| - POSTGRES_PASSWORD=${PG_STORAGE_DATABASE_PASSWORD} | ||
| - PGPORT=${PG_STORAGE_DATABASE_PORT} | ||
| volumes: | ||
| - pg_storage_data:/var/lib/postgresql/data | ||
| ports: | ||
| - "${PG_STORAGE_DATABASE_PORT}:${PG_STORAGE_DATABASE_PORT}" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready -U ${PG_STORAGE_DATABASE_USER} -d ${PG_STORAGE_DATABASE_NAME}"] | ||
| interval: 5s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| volumes: | ||
| pg_storage_data: | ||
| pg_data: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.