CapyDb CLI¶
A command-line tool for managing database migrations with Liquibase and Entity Framework Core.
π What is CapyDb?¶
CapyDb CLI addresses the challenge of managing database migrations consistently and efficiently, offering:
- β
Automatic configuration detection - automatically searches for
liquibase.properties - β Migration creation in Liquibase YAML format
- β Migration import from Entity Framework Core
- β Schema merge and consolidation automation
- β Safe execution with SQL execution plans
- β Multi-DBMS support (SQL Server, PostgreSQL, MySQL, Oracle)
- β Docker integration and CI/CD pipelines
- β Drift detection - identifies undocumented changes
- β Tag system - create and remove tags for versioning
- β Smart rollback - revert by count or to a specific tag
- β History squash - consolidates old migrations
- β Automatic author detection via Git/CI/CD
- β
Comprehensive diagnostics with
cap doctor - β Changelog validation before execution
- β INSERTs converter - converts SQL INSERTs to Liquibase format
- β Data seeding from CSV - automatically generates load data changesets
- β Intelligent type inference - detects column types from CSV headers
- β Data management - update, rollback, and reset seed data independently
π¦ Installation¶
Prerequisites¶
- .NET 8.0 SDK or higher
- Java 8+ (for Liquibase)
Global Installation¶
# Install via NuGet
dotnet tool install -g capydb.cli
# Verify installation
cap --version # 1.2.3
π Getting Started¶
1. Set Up Project¶
# Recommended structure
my-project/
βββ db/
β βββ changelog/
β βββ common/
β βββ db.changelog-master.yaml
β βββ liquibase.properties # β CLI auto-detects this!
βββ src/
βββ Infrastructure/ # Or any project structure
2. Check Prerequisites¶
cap doctor
3. Create First Migration¶
# Create a basic migration
cap migrations add create-users
# With specific author
cap migrations add create-products --author "Your Name"
4. Import from Entity Framework¶
cap migrations import-ef \
--assembly ./MyApp.dll \
--name CreateUsersTable \
--provider sqlserver
5. Run Migrations (Auto-Detection!)¶
# CLI automatically searches in ./db/changelog/liquibase.properties
cap plan # Generate execution plan
cap apply # Apply migrations
cap status # Check database status
# Create tag after deployment
cap tag v1.0.0
# Rollback if needed
cap rollback count 2
cap rollback to-tag v1.0.0
π‘ Automatic Configuration Detection (Enhanced!)¶
The CLI now features robust recursive search for liquibase.properties:
Search Priority:
1. ./db/changelog/liquibase.properties (recommended)
2. ./liquibase.properties (root directory)
3. ./config/liquibase.properties
4. ./database/liquibase.properties
5. ./src/*/db/changelog/liquibase.properties (monorepos!)
6. ./apps/*/db/changelog/liquibase.properties (monorepos!)
7. Recursive search in all subdirectories (excluding node_modules, .git)
Works perfectly on Windows, Linux, and macOS!
# Before (still works):
cap apply --defaults ./db/changelog/liquibase.properties
# Now (even simpler):
cap apply # Auto-detects in monorepos, nested structures, anywhere!
π Quick Examples¶
Recommended Project Structure¶
my-project/
βββ db/
β βββ changelog/
β β βββ common/
β β β βββ 20250924_120000__create-users.yaml
β β βββ db.changelog-master.yaml
β β βββ liquibase.properties # β Auto-detected!
β βββ drivers/
βββ src/
Auto-Generated Migration¶
# db/changelog/common/20250924_120000__create-users.yaml
databaseChangeLog:
- changeSet:
id: 20250924_120000-create-users
author: MoisΓ©s Drumand # β Detected via Git!
context: common
changes:
- createTable:
tableName: users
columns:
- column:
name: id
type: int
constraints:
primaryKey: true
Simplified Full Workflow¶
# 1. Create migration
cap migrations add create-users
# 2. Review what will be executed
cap plan
# 3. Apply to database
cap apply
# 4. Check status
cap status
# 5. Create version tag
cap tag v1.0.0
# 6. Revert if needed
cap rollback to-tag v1.0.0
Multiple Environments and DBMS¶
# Default environment (auto-detected)
cap apply
# PostgreSQL with custom file
cap apply --defaults ./db/changelog/liquibase-postgres.properties
# MySQL with Docker
cap apply --defaults ./db/changelog/liquibase-mysql.properties --docker
# Oracle
cap apply --defaults ./db/changelog/liquibase-oracle.properties
Converting SQL INSERTs¶
# Convert SQL INSERTs file to Liquibase format
cap convert-inserts --input ./data.sql --output ./changelog.yaml
# Specify table name
cap convert-inserts --input ./data.sql --table users --output ./changelog.yaml
Data Seeding from CSV¶
# Generate data-seed changelog from CSV
cap carga from-csv --input db/carga/Users.csv --table Users
# With author and auto-add to master changelog
cap carga from-csv \
--input db/carga/Countries.csv \
--table TabelaAuxiliarCountries \
--author "Your Name" \
--add-to-master
# Custom output location
cap carga from-csv \
--input db/carga/Cities.csv \
--table Cities \
--output db/changelog/custom/cities.yaml
# Automatic dependency resolution and ordering!
# When using --add-to-master, CapyDb automatically:
# β
Detects foreign keys from CSV column names (ending with "Id")
# β
Resolves table dependencies
# β
Orders changesets topologically (dependencies first)
# β
Prevents FK constraint violations during load
# Apply data seeds
cap carga update --defaults db/changelog/liquibase.properties
# Rollback data seeds
cap carga rollback --defaults db/changelog/liquibase.properties
# Check data seed status
cap carga status --defaults db/changelog/liquibase.properties
π§ͺ Tests¶
The project includes automated integration tests using Jest and Prisma.
# Run integration tests
cd tests/integration
npm install
npm test
# Tests with different DBMS
npm test -- --testMatch="**/migration.test.ts"
π Documentation¶
For complete documentation, visit: Documentation
π§ Main Commands¶
| Command | Description |
|---|---|
cap doctor |
Check prerequisites and connectivity |
cap migrations add <name> |
Create new migration with auto-detected author |
cap migrations import-ef |
Import migrations from EF Core |
cap migrations mergeschemas |
Consolidate multiple migrations |
cap plan |
Generate SQL execution plan |
cap apply |
Apply migrations to database |
cap status |
View database status and pending migrations |
cap validate |
Validate changelog syntax |
cap drift detect |
Detect undocumented changes |
cap tag <name> |
Create tag for versioning |
cap remove-tag <tag> |
Remove existing tag |
cap rollback count <N> |
Revert N migrations |
cap rollback to-tag <tag> |
Revert to a specific tag |
cap squash --tag <tag> |
Consolidate history up to a tag |
cap carga from-csv |
Generate data-seed changelog from CSV |
cap carga update |
Apply data seeds (label: data-seed) |
cap carga drop-all |
Remove all data and reapply |
cap carga reset |
Drop entire database and reapply all |
cap carga rollback |
Rollback last data changeset |
cap carga status |
Check data seed status |
cap bye |
Farewell with ASCII art 𦫠|
π¬ Contact¶
- π§ Email: evellynloraine@gmail.com
- πΌ LinkedIn: Evellyn Fernandes
- π± GitHub: lor4z
- π Documentation: CapyDb Docs
π License¶
This project is licensed under Apache 2.0.
π Useful Links¶
- NuGet Package: https://www.nuget.org/packages/capydb.cli/
- GitHub Repository: https://github.com/lor4z/capybara-db
- Current Version: 1.2.3
π What's New in v1.2.3¶
Data Seeding Features¶
- β
CSV to Changelog Generator -
cap carga from-csvcommand - β Intelligent Type Inference - Automatically detects UUID, BOOLEAN, TIMESTAMP, NUMERIC, STRING
- β Automatic Dependency Resolution - Detects FKs from CSV headers and orders tables automatically
- β Topological Sorting - Smart ordering prevents FK constraint violations during data load
- β Circular Dependency Detection - Warns about circular references between tables
- β Data Management Commands - update, drop-all, reset, rollback, status for seed data
- β Auto-add to Master - Option to automatically include in db.changelog-master.yaml
- β
Label-based Filtering - Uses
data-seedlabel for selective operations
Package Improvements¶
- β Embedded Dependencies - CapyDb.Core, Runner, and Writers are now embedded
- β No External Dependencies - Cleaner NuGet package with all DLLs included
- β Multi-target Support - Full support for .NET 8.0 and .NET 9.0
Previous Features (v1.0.7)¶
- β Enhanced file search on Windows - Fixed glob pattern issues
- β Robust recursive search - Finds liquibase.properties anywhere
- β Monorepo support - Works with complex project structures
- β Improved assembly detection - Better EF Core integration
- β Cross-platform compatibility - Tested on Windows, Linux, macOS
Developed with β€οΈ to simplify database migration management.