π CapyDb β Initial Setup¶
Step-by-step guide to configure CapyDb for the first time
π Prerequisites¶
- β Java 8+ installed
- β Database available (SQL Server, PostgreSQL or MySQL)
- β
CapyDb CLI installed (
cap --versionshould work)
π§ Step 1: Configure liquibase.properties¶
Edit db/changelog/liquibase.properties according to your environment:
SQL Server¶
url=jdbc:sqlserver://localhost:1433;databaseName=MyDatabase;trustServerCertificate=true
username=sa
password=YourPassword
changeLogFile=db.changelog-master.yaml
logLevel=INFO
contexts=common
PostgreSQL¶
url=jdbc:postgresql://localhost:5432/mydatabase
username=postgres
password=YourPassword
changeLogFile=db.changelog-master.yaml
logLevel=INFO
contexts=common
MySQL¶
url=jdbc:mysql://localhost:3306/mydatabase?useSSL=false&allowPublicKeyRetrieval=true
username=root
password=YourPassword
changeLogFile=db.changelog-master.yaml
logLevel=INFO
contexts=common
π§ Step 2: Test Your Configuration¶
cap doctor --defaults db/changelog/liquibase.properties
Expected output (example):
π©Ί CapyDb Doctor - Checking prerequisites...
β
Java: java version "17.0.7" 2023-04-18 LTS
β οΈ Docker: Not available (optional)
β
Defaults: db/changelog/liquibase.properties exists
β
Database: Connection OK
β
All prerequisites are OK!
If connection fails, verify:
1) DB service is running
2) Credentials are correct
3) URL (host/port/dbname) is correct
4) Network/firewall allows access
π³ Alternative: Use Docker¶
cap doctor --defaults db/changelog/liquibase.properties --docker
cap status --defaults db/changelog/liquibase.properties --docker
cap apply --defaults db/changelog/liquibase.properties --docker
Requirement: Docker Desktop installed
π Step 3: Create your first migration¶
cap migrations add my-first-migration
# Inspect the generated file:
cat db/changelog/common/20*__my-first-migration.yaml
Edit the file and add your changes, e.g.:
databaseChangeLog:
- changeSet:
id: 20250923_120000-my-first-migration
author: Your Name
context: common
changes:
- createTable:
tableName: users
columns:
- column:
name: id
type: BIGINT
autoIncrement: true
constraints:
primaryKey: true
nullable: false
- column:
name: name
type: VARCHAR(100)
constraints:
nullable: false
- column:
name: email
type: VARCHAR(255)
constraints:
nullable: false
unique: true
π Step 4: Test and Apply¶
# See what will run (without applying)
cap plan --defaults db/changelog/liquibase.properties --output plan.sql
# Review the plan
cat plan.sql
# Apply
cap apply --defaults db/changelog/liquibase.properties
# Check status
cap status --defaults db/changelog/liquibase.properties
π― Final Structure¶
db/
ββ changelog/
β ββ common/
β β ββ 20250923_120000__my-first-migration.yaml
β ββ db.changelog-master.yaml
β ββ liquibase.properties
β ββ liquibase.properties.example
ββ drivers/ # Optional if not using Docker
π οΈ Next Steps¶
Development¶
git config user.name "Your Full Name"
cap migrations add add-products-table
cap migrations add tune-performance-indexes
Production¶
cap plan --defaults liquibase.properties --output plan-prod.sql
cat plan-prod.sql
cap apply --defaults liquibase.properties
cap tag v1.0.0 --defaults liquibase.properties
CI/CD¶
export CAPY_AUTHOR="CI/CD Pipeline"
cap doctor --defaults liquibase.properties --docker
cap plan --defaults liquibase.properties --docker --output plan-ci.sql
β Security¶
Never commit passwords. Add to .gitignore:
db/changelog/liquibase.properties
*.log
plan*.sql
drift-report*.xml
Use environment variables in production:
url=jdbc:sqlserver://localhost:1433;databaseName=${DB_NAME};trustServerCertificate=true
username=${DB_USER}
password=${DB_PASSWORD}
Done! CapyDb is configured and running. For the complete reference, see the main guide.