https://github.com/krzko/restmigrate
🆙 Restmigrate is a tool for managing REST API configuration migrations, inspired by database schema migration tools.
https://github.com/krzko/restmigrate
api-migration apisix caddy cue cuelang database-migrations database-schema kong migration migrations rest rest-api
Last synced: 6 months ago
JSON representation
🆙 Restmigrate is a tool for managing REST API configuration migrations, inspired by database schema migration tools.
- Host: GitHub
- URL: https://github.com/krzko/restmigrate
- Owner: krzko
- License: apache-2.0
- Created: 2024-06-30T10:50:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-20T08:38:57.000Z (about 1 year ago)
- Last Synced: 2025-03-28T17:57:43.241Z (6 months ago)
- Topics: api-migration, apisix, caddy, cue, cuelang, database-migrations, database-schema, kong, migration, migrations, rest, rest-api
- Language: Go
- Homepage:
- Size: 565 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# restmigrate
`restmigrate` is a Go-based tool for managing and applying configuration changes to REST APIs in a systematic, version-controlled manner. It uses a migration-like approach similar to database schema migrations, allowing you to define, apply, and revert changes to your REST API configurations.
## Features
- Create, apply, and revert REST API configuration changes
- Support for multiple API gateways or generic API endpoints (e.g., Kong, APISIX, Generic)
- [CUE](https://cuelang.org/) language for defining migrations
- [OpenTelemetry](https://opentelemetry.io/) traces integration for observability### OpenTelemetry
`restmigrate` supports OpenTelemetry for distributed tracing, follow the [configuration](#configuration) section to enable it.
## Installation
### brew
Install [brew](https://brew.sh/) and then run:
```sh
brew install krzko/tap/restmigrate
```### Download Binary
Download the latest version from the [Releases](https://github.com/krzko/restmigrate/releases) page.
## Commands
* `create`: Create a new migration file
* `up`: Apply pending migrations
* `down`: Revert the last applied migration (use `--all` to revert all)
* `list`: Display applied migrations## Configuration
Set these environment variables to configure `restmigrate`:
* `OTEL_EXPORTER_OTLP_ENDPOINT`: OpenTelemetry exporter endpoint
* `OTEL_EXPORTER_OTLP_INSECURE`: Set to "true" for insecure connection
* `OTEL_SDK_ENABLED`: Set to "true" to enable OpenTelemetry (disabled by default)## Usage
### Creating a new migration
To create a new migration file:
```bash
restmigrate create
```This will create a new CUE file in the `migrations` directory with a timestamp prefix.
### Applying migrations
To apply all pending migrations, `--token` and `--type` are optional if the API does not require authentication:
```bash
restmigrate up --url --token --type
```### Reverting the last migration
To revert the most recently applied migration:
```bash
restmigrate down --url --token --type
```## Migration File Format
Migration files are written in CUE and should follow this structure:
```cue
migration: {
timestamp: 1625097600 // Unix timestamp
name: "add_new_endpoint"
up: {
"/api/v1/new_endpoint": {
method: "POST"
body: {
// Define the request body here
}
}
}
down: {
"/api/v1/new_endpoint": {
method: "DELETE"
}
}
}
```The `up` and `down` fields define the changes to be applied and reverted, respectively. The `timestamp` field is used to track the order of migrations.
Examples of migration files can be found in the [examples](/examples/) directory.
## Development
To set up the development environment:
1. Clone the repository:
```bash
git clone https://github.com/krzo/restmigrate.git
```2. Change to the project directory:
```bash
cd restmigrate
```3. Install dependencies:
```bash
go mod tidy
```4. Build the project:
```bash
make build
```