GithubHelp home page GithubHelp logo

krzko / restmigrate Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 591 KB

Restmigrate is a tool for managing REST API configuration migrations, inspired by database schema migration tools.

License: Apache License 2.0

Makefile 4.74% Go 93.60% Dockerfile 1.66%
api-migration apisix caddy cue cuelang database-migrations database-schema kong migration migrations rest rest-api

restmigrate's Introduction

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 language for defining migrations
  • OpenTelemetry traces integration for observability

OpenTelemetry

restmigrate supports OpenTelemetry for distributed tracing, follow the configuration section to enable it.

Distributed trace

Installation

brew

Install brew and then run:

brew install krzko/tap/restmigrate

Download Binary

Download the latest version from the 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:

restmigrate create <migration_name>

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:

restmigrate up --url <api_base_url> --token <api_token> --type <type>

Reverting the last migration

To revert the most recently applied migration:

restmigrate down --url <api_base_url> --token <api_token> --type <type>

Migration File Format

Migration files are written in CUE and should follow this structure:

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 directory.

Development

To set up the development environment:

  1. Clone the repository:
git clone https://github.com/krzo/restmigrate.git
  1. Change to the project directory:
cd restmigrate
  1. Install dependencies:
go mod tidy
  1. Build the project:
make build

restmigrate's People

Contributors

krzko avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.