Getting Started 🚀¶
This guide will walk you through setting up Jetbase from scratch. By the end, you'll have a fully working migration system for your database!
Prerequisites¶
Before you begin, make sure you have:
- Python 3.10+ installed
- A database (PostgreSQL, SQLite, Snowflake)
- pip or uv for installing packages
Installation¶
Install Jetbase using pip:
Note for Snowflake Users:
To use Jetbase with Snowflake, install the Snowflake extras:
Verify the installation:
You should see a list of available commands. 🎉
Setting Up Your Project¶
Step 1: Initialize Jetbase¶
Navigate to your project directory and run:
This creates a jetbase/ directory with the following structure:
jetbase/
├── migrations/ # Your SQL migration files go here
└── env.py # Database configuration
Step 2: Navigate to the Jetbase Directory¶
Important
All Jetbase commands must be run from inside the jetbase/ directory.
Step 3: Configure Your Database Connection¶
Open env.py and update the sqlalchemy_url with your database connection string:
Creating Your First Migration¶
Step 1: Generate a Migration File¶
Use the new command to create a migration file:
This creates a file like:
The filename format is: V{timestamp}__{description}.sql
Manual Migration Files
You can also create migration files manually if you prefer! Simply add your migration file to the jetbase/migrations/ folder and follow the required filename format:
V{version}__{description}.sql
Example:
V2.4__create_users_table.sql
Be sure your file starts with V, followed by a version (like 2.4), then __, a short description (use underscores for spaces), and ends with .sql.
Step 2: Write Your Migration SQL¶
Open the newly created file and add your SQL statements:
-- upgrade
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL
);
CREATE TABLE items (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL,
);
-- rollback
DROP TABLE items;
DROP TABLE users;
Migration File Structure
- The
-- rollbacksection contains only SQL to undo the migration, and any rollback statements must go after-- rollback
Step 3: Apply the Migration¶
Run the upgrade command:
Output:
Note:
You can also use another compatible driver if you prefer (such as
Jetbase uses SQLAlchemy under the hood to manage database connections.
For any database other than SQLite, you must install the appropriate Python database driver.
For example, to use Jetbase with PostgreSQL:asyncpg,pg8000, etc.).
Step 4: Verify the Migration¶
Check the migration status:
You'll see a table showing:
- ✅ Applied migrations
- 📋 Pending migrations (if any)
What's Next?¶
Now that you've set up your first migration, explore these topics:
- Writing Migrations — Learn about migration file syntax and best practices
- Commands Reference — Discover all available commands
- Rollbacks — Learn how to safely undo migrations
- Configuration Options — Customize Jetbase behavior
Quick Command Reference¶
| Command | Description |
|---|---|
init |
Initialize Jetbase in current directory |
new |
Create a new migration file |
upgrade |
Apply pending migrations |
rollback |
Undo migrations |
status |
Show migration status of all migration files (applied vs. pending) |
history |
Show migration history |
current |
Show latest version migrated |
lock-status |
Check if migrations are locked |
unlock |
Remove migration lock |
validate-checksums |
Verify migration file integrity |
validate-files |
Check for missing migration files |
fix |
Fix migration issues |
fix-files |
Fix missing migration files (same as validate-files --fix) |
fix-checksums |
Fix migration file checksums (same as validate-checksums --fix) |