Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanKiral committed Aug 7, 2024
1 parent 45e0438 commit c7b8aa5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 46 deletions.
73 changes: 27 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,27 @@
# Kontent.ai CLI migrations examples

The Kontent.ai CLI boilerplate aims to help with your first migration code. We've provided sample migration scripts in the `Migrations` folder. These scripts are written in Javascript and Typescript to show you the basic operations.

If you are missing your use case, you might find answers in the [Management API reference](https://kontent.ai/learn/reference/management-api-v2).

The Kontent.ai CLI tool supports only Javascript files, so if you write your migrations in Typescript or any other language you have to transpile your code before running.

## Installation

```sh
npm install
```

## Setup

Before you run your migrations, you need to store some information about the environment locally.

The environment is defined as a named pair of values. For example, "DEV" environment can be defined as a pair of a specific environment ID and Management API key. This named pair of values is stored within your local repository in a configuration file named `.environments.json`.

```sh
# Adds a 'DEV' environment reference.
kontent environment add --name DEV --environment-id "<YOUR_ENVIRONMENT_GUID>" --api-key "<YOUR_MANAGAMENT_API_KEY>"
```

## Usage

If you've set up an environment using the method above, you can use the prepared scripts to run all migrations in the `Migrations` directory.

```sh
# Executes all migration scripts in the 'Migrations' folder to the 'DEV' environment reference within your Kontent project.
npm run migrate:all
```

If you want to run a specific migration you can use also script defined in ```packages.json```

```sh
# Executes a migration script named 'my_migration'.
npm run migrate "my_migration"
```

**Tip**: For more information about Kontent migrations, see the [Kontent.ai CLI documentation](https://github.com/kontent-ai/cli/blob/master/README.md).

## Feedback & Contribution

Feedback & Contributions are welcomed. Feel free to take/start an issue & submit PR.
# Kontent.ai migrations examples

The Kontent.ai migrations boilerplate aims to provide a exemplary introduction in developing migrations using [Kontent.ai data-ops](https://github.com/kontent-ai/data-ops). Migrations allow you to perform any operation supported by the [Management API](https://kontent.ai/learn/reference/management-api-v2) through smaller executable scripts. This repository showcases various migration scenarios, including the creation of different entities. Each migration also includes a rollback function to reverse the changes made by the migration.

> [!NOTE]
> The migrations in this repository are written in `TypeScript` and must be transpiled before execution.
## Quickstart

1. Install required depencies
```sh
npm ci
```
1. Set up mandatory parameters for data-ops migrations:
1. Copy `exampleParams.json` and rename it to `migrationsParams.json`
1. Fill in the missing parameters for your environment.
> [!TIP]
> You can have multiple configuration files for different environments. For example, you might have one file for production and another for development.
1. Inspect the migrations in the `src` folder.
1. Examine prepared scripts in `package.json`.
1. Try out the scripts
- e.g. `npm run migrate:all` to run all of the migrations
> [!TIP]
> You can add additional parameters using --. For example, to rollback the next 5 migrations, use `npm run migrate:next -- 5 -b`.

> [!TIP]
> You can view all parameters by using `npm run data-ops -- migrations <command> -help`
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"migrate:range": "tsc && data-ops migrations run --configFile ./migrationsParams.json --range",
"migrate:next": "tsc && data-ops migrations run --configFile ./migrationsParams.json --next",
"migrate": "tsc && data-ops migration run --configFile ./migrationsParams.json -n",
"data-ops": "data-ops",
"lint": "eslint --fix \"src/*.ts\"",
"lint:check": "eslint \"src/*.ts\"",
"fmt": "dprint fmt",
Expand Down

0 comments on commit c7b8aa5

Please sign in to comment.