Skip to main content

Bamboo Database

A CLI tool for managing database structure (schema/migrations) and seed data across multiple database backends using raw SQL.

Features

  • Multi-Database Support: PostgreSQL, MySQL, and SQLite
  • Raw SQL Migrations: Full control with database-specific syntax
  • Combined Migrations: Schema changes and seed data in single atomic transactions
  • Per-Database Configuration: Separate migration folders for each database profile
  • Schema Generation: Auto-generate organized schema files from migrations
  • AI-Friendly Rules: Generate migration guidelines for AI assistants

Installation

# Basic installation (SQLite only)
pip install bamboo-database

# With PostgreSQL support
pip install bamboo-database[postgresql]

# With MySQL support
pip install bamboo-database[mysql]

# With all database backends
pip install bamboo-database[all]

# Development installation
pip install bamboo-database[dev]

Quick Start

1. Create Configuration

Create bamboo_database.toml in your project root:

[databases.default]
type = "postgresql"
host = "localhost"
port = 5432
database = "my_database"
user = "postgres"
password = "secret"
migrations_path = "./migrations/default"

[databases.analytics]
type = "mysql"
host = "localhost"
port = 3306
database = "analytics_db"
user = "root"
password = "secret"
migrations_path = "./migrations/analytics"

[databases.cache]
type = "sqlite"
path = "./cache.db"
migrations_path = "./migrations/cache"

2. Create Migration Files

Create migration files in your migrations folder:

-- migrations/default/0001_migrate_create_users.sql
BEGIN;

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    email VARCHAR(255) NOT NULL UNIQUE,
    name VARCHAR(100),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO users (id, email, name) VALUES
    (1, 'admin@example.com', 'Admin User')
ON CONFLICT (id) DO NOTHING;

COMMIT;

3. Run Migrations

# Migrate all databases
bamboodb migrate

# Migrate specific database
bamboodb migrate --database default

# Check migration status
bamboodb status

# List configured databases
bamboodb list-databases

CLI Commands

Command Description
bamboodb migrate Run pending migrations
bamboodb status Show migration status
bamboodb list-databases List configured databases
bamboodb generate-schema Generate schema files from migrations
bamboodb generate-rules Generate AI migration guidelines

Common Options

  • --database NAME - Target specific database (can be used multiple times)
  • --help - Show help for any command

Migration File Naming

Files are named with type prefixes:

  • {version}_migrate_{description}.sql - Schema changes (CREATE, ALTER, DROP)
  • {version}_seed_{description}.sql - Initial/reference data
  • {version}_index_{description}.sql - Index creation

Version format: 4-digit zero-padded (0001, 0002, 0003...)

Examples:

  • 0001_migrate_create_users.sql
  • 0002_seed_insert_admin_user.sql
  • 0003_index_users_email_idx.sql

Idempotent Seed Data

Use database-specific syntax for idempotent inserts:

PostgreSQL:

INSERT INTO users (id, email) VALUES (1, 'admin@example.com')
ON CONFLICT (id) DO NOTHING;

MySQL:

INSERT IGNORE INTO users (id, email) VALUES (1, 'admin@example.com');

SQLite:

INSERT OR IGNORE INTO users (id, email) VALUES (1, 'admin@example.com');

Python API

from bamboo_database import load_config, create_adapter

# Load configuration
config = load_config()

# Get a database profile
profile = config.get_database("default")

# Create an adapter
with create_adapter(profile) as adapter:
    adapter.execute("SELECT * FROM users")
    results = adapter.fetch_all("SELECT * FROM users")

Requirements

  • Python 3.10+
  • Database drivers (optional):
    • PostgreSQL: psycopg[binary]
    • MySQL: mysql-connector-python
    • SQLite: Built-in

License

MIT License - see LICENSE for details.

Metadata

Release files for bamboo-database 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bamboo-database 0.1.2
File Size Uploaded Provenance
bamboo_database-0.1.2.tar.gz 21.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bamboo-database 0.1.2
File Interpreter ABI Platform
bamboo_database-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 51.8 kB

Release files / bamboo_database-0.1.2.tar.gz

Download URL bamboo_database-0.1.2.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4c1fea2b5e871fc1633a08d69e9d71c243abf89b78c3f51d09ad27ce064ce29b
BLAKE2b-256 checksum
How to use checksums
6af6f209ab8424d73027c0f8464ef9b05677595e54b5df3d95a2b043f5267e81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / bamboo_database-0.1.2-py3-none-any.whl

Download URL bamboo_database-0.1.2-py3-none-any.whl
Size 30.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d8a969cdbe41d4057cd0d698a0acfb9c574611beff20d42826b0678cdf9b1e6
BLAKE2b-256 checksum
How to use checksums
52b73783d9ed81b241d960bd34d54260b1af9761664a7a61605da188e18765b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for bamboo-database 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page