Skip to content

Commit

Permalink
🔨 add readme, tweak script
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Aug 13, 2024
1 parent 3dbf32c commit 5bb7b6f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 19 additions & 0 deletions devTools/syncGraphersToR2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# syncGraphersToR2

This script, `syncGraphersToR2.ts`, is used to sync grapher configurations from the `chart_configs` table to R2 storage. It supports different commands to perform specific tasks.

## Available Commands

- `sync`: Sync all grapher configs from the DB to R2 buckets, both upserting into R2 and deleting obsolete ones from R2. This command is useful for production if the R2 storage should get out of sync with the database and/or to initially fill R2. It can't be used to fill local development R2 buckets.
- `store-dev-by-slug`: Fetch a grapher config by slug from the `chart_configs` table and store it in the local dev R2 storage. This is useful for your local dev environment when you want to test the CF Pages Functions that need R2 files to exist. CF Pages Functions using R2 bindings can (as of 2024-08-13) not access real remote R2 buckets.

## Usage

To run the script, use the following command:

```sh
yarn syncGraphersToR2 [command] [options]
```

Options
--dry-run: Don't make any actual changes to R2.
5 changes: 3 additions & 2 deletions devTools/syncGraphersToR2/syncGraphersToR2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ async function storeDevBySlug(
}

await knexReadonlyTransaction(async (trx) => {
// Fetch the chart config from the DB by slug
const chart = await knexRawFirst<DbRawChartConfig>(
trx,
`SELECT full FROM chart_configs WHERE slug = ?`,
`SELECT full FROM chart_configs WHERE slug = ? and full ->> '$.isPublished' = "true"`,
[slug]
)
if (!chart) {
Expand Down Expand Up @@ -352,7 +353,7 @@ if (parsedArgs["h"]) {
Commands:
sync: Sync grapher configs to R2
store-dev-by-slug: Dummy implementation for store-dev-by-slug`
store-dev-by-slug: Fetch a grapher config by slug from the chart_configs table and store it the local dev R2 storage`
)
} else {
main(parsedArgs)
Expand Down

0 comments on commit 5bb7b6f

Please sign in to comment.