Skip to content

Commit

Permalink
Improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
u12206050 committed Nov 13, 2023
1 parent 5f84043 commit c1de365
Showing 1 changed file with 37 additions and 27 deletions.
64 changes: 37 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,9 @@ Upon installing configure what data you wish to export from the DB and be able t

**IMPORTANT** Always be careful with what you export and commit to your repository.

## Install (via NPM)
# Install

1. `npm install directus-extension-schema-sync`
2. Then run `directus schema-sync install` to install the extension's columns in the database and add the config folder
3. Edit the `config.js` in the schema directory and add your collections you want to sync
4. Finally run `directus schema-sync export` to export the schema and data from the Directus API

In production it is advised to set `SCHEMA_SYNC` to `IMPORT` and in local development to `BOTH`.

View changelog for more information. [CHANGELOG.md](https://github.com/bcc-code/directus-schema-sync/blob/main/CHANGELOG.md)

### Notes

If this is the **first extension you are installing**, then a new `package.json` file will be created in the extensions folder. In order for everything to work you need to add the following to the `package.json` file: `"type": "module"`. This is because the extension uses ES6 modules.

## Install (via Docker)
## via Docker

If you don't already have a Dockerfile, you can use the following [instructions to get started.](https://docs.directus.io/extensions/installing-extensions.html)

Expand All @@ -44,12 +31,35 @@ Update your Dockerfile to include the following:
```dockerfile
RUN pnpm install directus-extension-schema-sync
COPY ./schema-sync ./schema-sync
COPY ./extensions ./extensions
```

## Usage
During local development, add the `schema-sync` folder as volumn to the `docker-compose` file.

```yaml
volumes:
- ./schema-sync:/directus/extensions/schema-sync
```

Upon first time running the container, run the following command to install the extension's columns in the database and add the config folder. (Replace the first `directus` with the name of your container if it is different)

```bash
docker-compose exec directus npx directus schema-sync install
```

### Tips
## via NPM (Assuming you are running Directus via NPM)

1. `npm install directus-extension-schema-sync`
2. Then run `directus schema-sync install` to install the extension's columns in the database and add the config folder
3. Edit the `config.js` in the schema directory and add your collections you want to sync
4. Finally run `directus schema-sync export` to export the schema and data from the Directus API

In production it is advised to set `SCHEMA_SYNC` to `IMPORT` and in local development to `BOTH`.

View changelog for more information. [CHANGELOG.md](https://github.com/bcc-code/directus-schema-sync/blob/main/CHANGELOG.md)

# Usage

## Tips

**Order matters** when importing and exporting. For example if you have a collection (A) with a relation to another collection (B), then ensure in the config that collection (B) comes first. This is so when we import, we first import B, then A. Deletions happen afterward in the reverse order.

Expand Down Expand Up @@ -81,7 +91,15 @@ onImport: async (item, itemsSrv) => {
},
```

### CI Commands
## Environment Variables

| Variable | Description | Default |
| -------- | ----------- | ------- |
| `SCHEMA_SYNC` | Set to automatically do **IMPORT****EXPORT** or **BOTH** | `null` |
| `SCHEMA_SYNC_CONFIG` | (optional) An additional config file to use in addition, eg. `test_config.js` | `null` |


## CI Commands

Besides auto importing and exporting, you can also run the commands manually.

Expand All @@ -94,14 +112,6 @@ Besides auto importing and exporting, you can also run the commands manually.
| `hash`| Recalculate the hash for all the data files (already happens after export) |
| `install` | Install the extension's columns in the database and add the config folder (options: `force`) |

### Environment Variables

| Variable | Description | Default |
| -------- | ----------- | ------- |
| `SCHEMA_SYNC` | Set to automatically do **IMPORT****EXPORT** or **BOTH** | `null` |
| `SCHEMA_SYNC_CONFIG` | An additional config file to use in addition, eg. `test_config.js` | `null` |


## Contributing

Contributions are welcome. Please open an issue or pull request.

0 comments on commit c1de365

Please sign in to comment.