oxbase

0.0.1-canary.2 • Public • Published

Oxbase

A modern framework for building full-stack applications with TypeScript.

Features

  • Type-safe database operations with SQLite
  • Multi-schema support with separate database files
  • Automatic migration generation similar to Drizzle CLI
  • Interactive schema management with destructive operation prompts
  • Modern CLI with comprehensive commands

CLI Commands

Development

# Start development server
ob dev

# Build for production
ob build

Database Management

# Apply migrations
ob migrate

# Apply migrations for specific schema
ob migrate --schema myapp

# Check migration status
ob migrate status

# Check migration status for specific apps
ob migrate status --apps myapp,otherapp

# Push schema changes (interactive)
ob push

# Push schema changes for specific apps
ob push --apps myapp,otherapp

# Force push (no prompts)
ob push --apps myapp --force

Migration Generation

# Generate migration by comparing databases
ob generate myapp

# Generate blank migration file
ob generate myapp --blank

Type System

# Type check
ob typecheck

# Generate types
ob typegen

Migration System

Oxbase provides a comprehensive migration system similar to Drizzle CLI with built-in migration tracking:

Migration Tracking

The system automatically tracks applied migrations using a __oxbase_migrations table in each database schema:

  • Prevents duplicate migrations: Only applies migrations that haven't been applied yet
  • Migration status: Check which migrations are pending or already applied
  • Checksum verification: Detects if migration files have been modified
  • Timestamp tracking: Records when each migration was applied

Migration Generation

The generate command creates SQL migration files by comparing the current database state with the desired schema:

# Generate migration for an app
ob generate myapp

This will:

  1. Create temporary databases (temp_migrate and temp_push)
  2. Apply existing migrations to temp_migrate (current state)
  3. Apply schema push to temp_push (desired state)
  4. Compare the two databases and generate SQL migration files
  5. Handle destructive operations with interactive prompts
  6. Create migration files in ./apps/myapp/migrations/
  7. Clean up temporary databases

Migration File Structure

project/
├── migrations/
│   ├── main/
│   │   ├── 20241201T120000_main_migration.sql
│   │   └── 20241201T130000_main_update.sql
│   └── myapp/
│       ├── 20241201T140000_myapp_migration.sql
│       └── 20241201T150000_myapp_update.sql
└── apps/
    └── myapp/
        └── migrations/
            ├── 001_legacy_migration.sql
            └── 002_legacy_update.sql

Supported SQL Operations

  • CREATE TABLE
  • DROP TABLE
  • ALTER TABLE ADD COLUMN
  • ALTER TABLE DROP COLUMN
  • ALTER TABLE RENAME COLUMN
  • ⚠️ ALTER TABLE ALTER COLUMN (requires table recreation in SQLite)

Multi-Schema Support

Each schema gets its own database file with migration tracking:

.oxbase_data/database/
├── main/
│   └── main.db (includes __oxbase_migrations table)
├── myapp/
│   └── myapp.db (includes __oxbase_migrations table)
└── otherapp/
    └── otherapp.db (includes __oxbase_migrations table)

Project Structure

project/
├── apps/
│   ├── myapp/
│   │   ├── myapp.app.ts
│   │   ├── entities/
│   │   │   └── user.entity.ts
│   │   └── migrations/
│   │       └── 001_initial.sql
│   └── otherapp/
│       └── otherapp.app.ts
├── migrations/
│   ├── main/
│   └── myapp/
├── oxbase.config.ts
└── package.json

Configuration

Create oxbase.config.ts in your project root:

import { defineConfig } from 'oxbase';

export default defineConfig({
  // Your configuration here
});

Getting Started

  1. Install Oxbase:
npm install oxbase
  1. Create your first app:
mkdir -p apps/myapp
  1. Create an app configuration:
// apps/myapp/myapp.app.ts
export default {
  name: 'myapp',
  // Your app configuration
};
  1. Generate and apply migrations:
# Generate migration by comparing current state with desired schema
ob generate myapp

# Apply the generated migration
ob migrate

# Or apply migrations for specific schema
ob migrate --schema myapp

Complete Migration Workflow

  1. Define your entities in apps/myapp/entities/
  2. Generate migration to see what changes are needed:
    ob generate myapp
  3. Review the generated SQL in apps/myapp/migrations/
  4. Apply the migration:
    ob migrate
  5. Push schema changes (if needed):
    ob push --apps myapp

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i oxbase

Weekly Downloads

2

Version

0.0.1-canary.2

License

none

Unpacked Size

333 kB

Total Files

75

Last publish

Collaborators

  • ppenter