inceptools-cli

command module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2026 License: GPL-2.0, GPL-3.0 Imports: 5 Imported by: 0

README ΒΆ

⚑ inceptools

A powerful, zero-dependency database migration CLI for Go

CI Latest Release License Go Version


inceptools is a lightweight CLI tool that manages database schema migrations with automatic version tracking, rollback support, and multi-database compatibility β€” all powered by GORM.

✨ Features

  • πŸ—„οΈ Multi-Database Support β€” PostgreSQL, MySQL, SQLite, SQL Server, ClickHouse
  • πŸ“‚ File-Based Migrations β€” Plain SQL up/down scripts, versioned and ordered
  • πŸ”„ Smart Sync β€” Auto-detects removed migration files and rolls them back
  • βͺ Granular Rollback β€” Roll back all or N steps with a single command
  • βš™οΈ Simple Configuration β€” One icpt.json file, sensible defaults
  • 🧾 Full History β€” Every migration run is tracked in the database

πŸ—ƒοΈ Supported Databases

Database Dialect Values Driver
PostgreSQL postgres, pg gorm.io/driver/postgres
MySQL mysql gorm.io/driver/mysql
SQLite sqlite github.com/glebarez/sqlite
SQL Server sqlserver, mssql gorm.io/driver/sqlserver
ClickHouse clickhouse gorm.io/driver/clickhouse

πŸ—οΈ Project Structure

The project follows a clean, modular architecture:

  • main.go: Lightweight entry point and CLI dispatcher.
  • src/cmd/: Individual command handlers (init, create, migrate, etc.).
  • src/db/: Core database migration engine and dialect support.
  • src/config/: Configuration management (icpt.json).
  • test/: Comprehensive test suite for database and CLI logic.

πŸ“¦ Installation

Go Install

go install github.com/IncepTools/inceptools-cli@latest
brew install inceptools/tap/inceptools

APT (Ubuntu/Debian)

Download the .deb package from the Releases page and install:

sudo dpkg -i inceptools_*.deb

Pre-built Binaries

Grab the latest release for your platform from the Releases page.

curl -fsSL https://raw.githubusercontent.com/IncepTools/inceptools-cli/main/install.sh

πŸ› οΈ Usage

1. Initialize

inceptools init

Creates a migrations/ directory and icpt.json config.

2. Create Migration

inceptools create

Interactively prompts for a topic and generates .up.sql and .down.sql files.

3. Run Migrations

inceptools migrate [database_url]

If database_url is omitted, it uses the environment variable defined in icpt.json.

4. Rollback

inceptools down [database_url] --steps 1

5. Update CLI

inceptools update

000001_create_users_table.up.sql

000001_create_users_table.down.sql


Follow the prompt to enter a topic for your migration.

Create an `icpt.json` in your project root:

```json
{
  "env_variable": "DATABASE_URL",
  "migration_path": "./migrations",
  "dialect": "postgres"
}
Key Default Description
env_variable DATABASE_URL Environment variable holding the database DSN
migration_path ./migrations Directory where migration SQL files are stored
dialect postgres Database dialect (see table above)

2. Create a Migration

inceptools create
# Enter migration topic (e.g., add_email_json): create_users_table
#
# Created:
#   000001_create_users_table.up.sql
#   000001_create_users_table.down.sql

Edit the generated files in ./migrations/:

000001_create_users_table.up.sql

CREATE TABLE users (
    id    SERIAL PRIMARY KEY,
    name  VARCHAR(255) NOT NULL,
    email VARCHAR(255) UNIQUE NOT NULL
);

000001_create_users_table.down.sql

DROP TABLE IF EXISTS users;

3. Apply Migrations

# Using the environment variable from icpt.json
export DATABASE_URL="postgres://user:pass@localhost:5432/mydb?sslmode=disable"
inceptools migrate

# Or pass the DSN directly
inceptools migrate "postgres://user:pass@localhost:5432/mydb?sslmode=disable"

4. Rollback Migrations

# Roll back the last migration
inceptools down -steps 1

# Roll back all migrations
inceptools down

# With explicit DSN
inceptools down -steps 2 "postgres://user:pass@localhost:5432/mydb"

πŸ“ Project Structure

your-project/
β”œβ”€β”€ icpt.json                          # Configuration
β”œβ”€β”€ migrations/
β”‚   β”œβ”€β”€ 000001_create_users.up.sql     # Up migration
β”‚   β”œβ”€β”€ 000001_create_users.down.sql   # Down migration
β”‚   β”œβ”€β”€ 000002_add_email.up.sql
β”‚   └── 000002_add_email.down.sql
└── ...

πŸ”„ How Migration Sync Works

When you run inceptools migrate, the tool performs a two-phase sync:

  1. Phase A β€” Cleanup: Scans for migrations that were previously applied but whose files have been removed locally. These are automatically rolled back using the stored down-script.
  2. Phase B β€” Apply: Applies any new or previously rolled-back migrations in version order.

This ensures your database schema always mirrors the migration files in your project.


πŸ“‚ Examples

Explore practical integration examples in the examples/ directory:

  • Go Project: Integration using Makefile and standard Go layout.
  • Node.js Project: Integration using npm scripts and package.json.

🀝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

πŸ” Security

To report a vulnerability, please see our Security Policy.

πŸ“„ License

Copyright Β© 2025 IncepTools

This project is licensed under the GNU General Public License v3.0 β€” see the LICENSE file for details.

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis
examples
go-project command
examples/go-project/main.go
examples/go-project/main.go
src
cmd
db
ui

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL