Add CLI support
Description
Add a CLI for @deessejs/collections to manage database operations and development workflows.
Current Status
The following functions already exist in @deessejs/collections but need implementation:
// packages/core/src/migrations.ts
export const push = async (adapter: PgAdapter, collections: Collection[]) => { /* TODO */ }
export const generate = async (adapter: PgAdapter, collections: Collection[]) => { /* TODO */ }
export const migrate = async (adapter: PgAdapter) => { /* TODO */ }
These functions should wrap drizzle-kit CLI commands using child_process.spawn() since drizzle-kit doesn't provide a programmatic API.
Scope: Phase 1
For now, only implement the core database commands:
Database Commands
# Push schema to database (development mode)
npx @deessejs/collections db:push
# Generate migration files
npx @deessejs/collections db:generate
# Apply migrations (production)
npx @deessejs/collections db:migrate
Global Options
# Dry-run mode (simulation)
collections db:push --dry-run
# Specify config file
collections --config path/to/config.ts db:push
# Verbose output
collections db:push --verbose
Implementation Notes
drizzle-kit Integration
Since drizzle-kit doesn't provide a programmatic API, the CLI commands should use child_process.spawn() to execute drizzle-kit:
import { spawn } from 'child_process'
async function runDrizzleKit(args: string[]) {
return new Promise((resolve, reject) => {
const child = spawn('npx', ['drizzle-kit', ...args], {
stdio: 'inherit',
shell: true
})
child.on('close', (code) => {
if (code === 0) resolve(code)
else reject(new Error(`drizzle-kit exited with code ${code}`))
})
})
}
Config File
The CLI should read the collections config from a standard location:
./collections/config.ts
- Or path specified via
--config option
Output Directory
Generated schema should be written to:
./drizzle (default)
- Or path specified via
--out option
Future Scope (Not Implemented)
- Scaffolding commands (
create collection, add field)
- Development commands (
validate, inspect)
- Seeders (
db:seed)
Design Principles
- Single Entry Point: CLI reads config automatically from defined file
- Global Options:
--config, --dry-run, --verbose
- Good UX: Clear error messages
Motivation
The CLI provides essential developer tools for managing database schema and migrations.
Add CLI support
Description
Add a CLI for
@deessejs/collectionsto manage database operations and development workflows.Current Status
The following functions already exist in
@deessejs/collectionsbut need implementation:These functions should wrap drizzle-kit CLI commands using
child_process.spawn()since drizzle-kit doesn't provide a programmatic API.Scope: Phase 1
For now, only implement the core database commands:
Database Commands
Global Options
Implementation Notes
drizzle-kit Integration
Since drizzle-kit doesn't provide a programmatic API, the CLI commands should use
child_process.spawn()to execute drizzle-kit:Config File
The CLI should read the collections config from a standard location:
./collections/config.ts--configoptionOutput Directory
Generated schema should be written to:
./drizzle(default)--outoptionFuture Scope (Not Implemented)
create collection,add field)validate,inspect)db:seed)Design Principles
--config,--dry-run,--verboseMotivation
The CLI provides essential developer tools for managing database schema and migrations.