#!/usr/bin/env node import { Command } from 'commander'; /** * CLI Types * * Type definitions for the postgres.do CLI. * * @module cli/types */ /** * Base CLI options */ interface BaseCLIOptions { command: string; url?: string | undefined; help?: boolean | undefined; verbose?: boolean | undefined; json?: boolean | undefined; } /** * Migration CLI options */ interface MigrateCLIOptions extends BaseCLIOptions { migrationsDir?: string | undefined; name?: string | undefined; toVersion?: number | undefined; steps?: number | undefined; force?: boolean | undefined; dryRun?: boolean | undefined; doId?: string | undefined; migrationFormat?: 'ts' | 'sql' | undefined; } /** * Schema diff CLI options */ interface SchemaDiffCLIOptions extends BaseCLIOptions { from?: string | undefined; to?: string | undefined; schema?: string | undefined; includeTables?: string[] | undefined; excludeTables?: string[] | undefined; includeIndexes?: boolean | undefined; ignoreCase?: boolean | undefined; generateMigration?: boolean | undefined; migrationName?: string | undefined; migrationFormat?: 'ts' | 'sql' | undefined; migrationsDir?: string | undefined; safeMode?: boolean | undefined; wrapInTransaction?: boolean | undefined; exitCode?: boolean | undefined; noColor?: boolean | undefined; } /** * Schema sync (push/pull) CLI options */ interface SchemaSyncCLIOptions extends BaseCLIOptions { input?: string | undefined; output?: string | undefined; schema?: string | undefined; includeRelations?: boolean | undefined; includeIndexes?: boolean | undefined; includeTables?: string[] | undefined; excludeTables?: string[] | undefined; generateTypes?: boolean | undefined; dryRun?: boolean | undefined; force?: boolean | undefined; noColor?: boolean | undefined; doId?: string | undefined; } /** * Dev server CLI options */ interface DevCLIOptions extends BaseCLIOptions { migrationsDir?: string | undefined; seedsDir?: string | undefined; port?: number | undefined; dataDir?: string | undefined; persist?: boolean | undefined; watch?: boolean | undefined; wrangler?: boolean | undefined; seed?: boolean | undefined; doId?: string | undefined; } /** * Migration dashboard CLI options */ interface MigrateDashboardCLIOptions extends BaseCLIOptions { apiUrl?: string | undefined; apiKey?: string | undefined; watch?: boolean | undefined; refreshInterval?: number | undefined; showVersion?: number | undefined; showFailed?: boolean | undefined; listOperations?: boolean | undefined; operationId?: string | undefined; retry?: string | undefined; limit?: number | undefined; } /** * Migrate Command * * Run pending migrations against a database. * * @module cli/commands/migrate */ /** * Run migrations command */ declare function runMigrate(options: MigrateCLIOptions): Promise; /** * Migrate Status Command * * Show the current migration status of a database. * * @module cli/commands/migrate-status */ /** * Show migration status command */ declare function runMigrateStatus(options: MigrateCLIOptions): Promise; /** * Migrate Rollback Command * * Rollback migrations from a database. * * @module cli/commands/migrate-rollback */ /** * Rollback migrations command */ declare function runMigrateRollback(options: MigrateCLIOptions): Promise; /** * Migrate Create Command * * Create a new migration file. * * @module cli/commands/migrate-create */ /** * Create migration command */ declare function runMigrateCreate(options: MigrateCLIOptions): Promise; /** * Migrate Validate Command * * Validate migrations before deployment. * Performs syntax checking, destructive operation detection, * and best practice enforcement. * * @module cli/commands/migrate-validate */ /** * Migrate validate command */ declare function runMigrateValidate(options: MigrateCLIOptions): Promise; /** * Migrate Dry Run Command * * Preview migrations that would be applied without executing them. * Shows the SQL that would be run and affected tables. * * @module cli/commands/migrate-dry-run */ /** * Migrate dry-run command */ declare function runMigrateDryRun(options: MigrateCLIOptions): Promise; /** * Migrate Dashboard Command * * Displays a real-time dashboard showing migration progress across all DOs. * Provides version distribution, failed migration tracking, and velocity metrics. * * @module cli/commands/migrate-dashboard */ /** * Run the migrate:dashboard command */ declare function runMigrateDashboard(options: MigrateDashboardCLIOptions): Promise; /** * External Migration Commands * * CLI commands for migrating from external PostgreSQL providers (Neon, Supabase) * to postgres.do (PGLite). * * @module cli/commands/migrate-from-external */ /** * Options for migrate from-neon command */ interface MigrateFromNeonOptions { /** Neon connection string */ connectionString: string; /** Output directory for migration files */ outputDir?: string; /** Include data migration */ includeData?: boolean; /** Specific tables to migrate */ tables?: string[]; /** Tables to exclude */ excludeTables?: string[]; /** Batch size for data migration */ batchSize?: number; /** Validate schema before migration */ validate?: boolean; /** Output as JSON */ json?: boolean; /** Verbose output */ verbose?: boolean; /** Dry run - don't actually write files */ dryRun?: boolean; /** Validate data integrity after migration */ validateIntegrity?: boolean; } /** * Options for migrate from-supabase command */ interface MigrateFromSupabaseOptions { /** Supabase connection string */ connectionString: string; /** Output directory for migration files */ outputDir?: string; /** Include data migration */ includeData?: boolean; /** Specific tables to migrate */ tables?: string[]; /** Tables to exclude (default: Supabase internal tables) */ excludeTables?: string[]; /** Batch size for data migration */ batchSize?: number; /** Validate schema before migration */ validate?: boolean; /** Output as JSON */ json?: boolean; /** Verbose output */ verbose?: boolean; /** Dry run - don't actually write files */ dryRun?: boolean; /** Validate data integrity after migration */ validateIntegrity?: boolean; } /** * Run migrate from-neon command */ declare function runMigrateFromNeon(options: MigrateFromNeonOptions): Promise; /** * Run migrate from-supabase command */ declare function runMigrateFromSupabase(options: MigrateFromSupabaseOptions): Promise; /** * Run schema validation command */ declare function runMigrateValidateSchema(options: { connectionString: string; json?: boolean; verbose?: boolean; strict?: boolean; }): Promise; /** * Options for pg_dump import */ interface ImportPgDumpOptions { /** Path to the pg_dump file */ file: string; /** Output directory for transformed files */ outputDir?: string; /** Validate schema compatibility */ validate?: boolean; /** Output as JSON */ json?: boolean; /** Verbose output */ verbose?: boolean; /** Dry run - don't write files */ dryRun?: boolean; } /** * Run pg_dump import command */ declare function runImportPgDump(options: ImportPgDumpOptions): Promise; /** * Options for query compatibility test */ interface QueryCompatibilityTestOptions { /** Path to file containing test queries (one per line) */ queriesFile?: string; /** Individual queries to test */ queries?: string[]; /** Output as JSON */ json?: boolean; /** Verbose output */ verbose?: boolean; } /** * Run query compatibility test command */ declare function runQueryCompatibilityTest(options: QueryCompatibilityTestOptions): Promise; /** * Schema Diff CLI Command * * Compare database schemas and generate migration SQL. * * @example * ```bash * # Diff two databases * npx postgres.do schema:diff --from $LOCAL_DB_URL --to $PROD_DB_URL * * # Generate migration from diff * npx postgres.do schema:diff --from $LOCAL_DB_URL --to $PROD_DB_URL --generate-migration * * # Output as JSON * npx postgres.do schema:diff --from $LOCAL_DB_URL --to $PROD_DB_URL --json * ``` * * @module cli/commands/schema-diff */ /** * Run schema:diff command */ declare function runSchemaDiff(options: SchemaDiffCLIOptions): Promise; /** * Schema Sync CLI Commands * * Pull and push database schemas. * * @example * ```bash * # Pull schema from database to local file * npx postgres.do schema:pull --url $DATABASE_URL --output ./schema.ts * * # Push local schema to database (diff and apply) * npx postgres.do schema:push --url $DATABASE_URL --input ./schema.ts * * # Push with dry run * npx postgres.do schema:push --url $DATABASE_URL --input ./schema.ts --dry-run * ``` * * @module cli/commands/schema-sync */ /** * Run schema:pull command * * Pull schema from a database and generate Drizzle schema file */ declare function runSchemaPull(options: SchemaSyncCLIOptions): Promise; /** * Run schema:push command * * Push local schema to database by comparing and applying changes */ declare function runSchemaPush(options: SchemaSyncCLIOptions): Promise; /** * Dev Command * * Start local development environment for postgres.do with: * - Local PostgreSQL using PGLite * - Migration watching and hot reload * - Optional wrangler integration * * @module cli/commands/dev */ /** * Start the dev server */ declare function runDev(options: DevCLIOptions): Promise; /** * Dev Reset Command * * Reset the local development database to a clean state: * - Drop all tables and recreate * - Optionally re-run seeds * - Can target specific DO instance * * @module cli/commands/dev-reset */ /** * Reset the development database */ declare function runDevReset(options: DevCLIOptions): Promise; /** * CLI Output Formatter * * Provides formatting utilities for JSON, table, and plain text output. * * @module cli/output */ /** * Output format type */ type OutputFormat = 'json' | 'table' | 'plain'; /** * Output formatter options */ interface OutputOptions { format?: OutputFormat | undefined; noColor?: boolean | undefined; verbose?: boolean | undefined; } /** * Create Command * * Create a new database on postgres.do * * @module cli/commands/create */ /** * Create command options */ interface CreateOptions extends OutputOptions { /** Database name */ name: string; /** Region for the database */ region?: string | undefined; /** Database plan */ plan?: 'free' | 'pro' | 'enterprise' | undefined; /** Wait for database to be ready */ wait?: boolean | undefined; /** Timeout for waiting (ms) */ timeout?: number | undefined; /** API URL override */ apiUrl?: string | undefined; } /** * Create a new database */ declare function runCreate(options: CreateOptions): Promise; /** * List all databases */ declare function runList(options: OutputOptions & { apiUrl?: string; }): Promise; /** * Get database info */ declare function runInfo(nameOrId: string, options: OutputOptions & { apiUrl?: string; }): Promise; /** * Delete a database */ declare function runDelete(nameOrId: string, options: OutputOptions & { apiUrl?: string; force?: boolean; }): Promise; /** * Backup Command * * Export/backup a database from postgres.do * * @module cli/commands/backup */ /** * Backup format type */ type BackupFormat = 'sql' | 'custom' | 'directory' | 'tar'; /** * Backup command options */ interface BackupOptions extends OutputOptions { /** Database name or ID */ name: string; /** Output file path */ output?: string | undefined; /** Backup format */ backupFormat?: BackupFormat | undefined; /** Include schema only (no data) */ schemaOnly?: boolean | undefined; /** Include data only (no schema) */ dataOnly?: boolean | undefined; /** Specific tables to backup (comma-separated) */ tables?: string | undefined; /** Tables to exclude (comma-separated) */ excludeTables?: string | undefined; /** Compress output */ compress?: boolean | undefined; /** API URL override */ apiUrl?: string | undefined; } /** * Run backup command */ declare function runBackup(options: BackupOptions): Promise; /** * List available backups for a database */ declare function runBackupList(name: string, options: OutputOptions & { apiUrl?: string; }): Promise; /** * Download a specific backup */ declare function runBackupDownload(name: string, backupId: string, options: OutputOptions & { apiUrl?: string; output?: string; }): Promise; /** * Restore Command * * Import/restore a database to postgres.do * * @module cli/commands/restore */ /** * Restore command options */ interface RestoreOptions extends OutputOptions { /** Input file path */ file: string; /** Target database name (will create if doesn't exist) */ database?: string | undefined; /** Drop existing objects before restore */ clean?: boolean | undefined; /** Create database before restore */ create?: boolean | undefined; /** Restore data only (no schema) */ dataOnly?: boolean | undefined; /** Restore schema only (no data) */ schemaOnly?: boolean | undefined; /** Specific tables to restore (comma-separated) */ tables?: string | undefined; /** Continue on error */ ignoreErrors?: boolean | undefined; /** Number of parallel jobs */ jobs?: number | undefined; /** API URL override */ apiUrl?: string | undefined; } /** * Run restore command */ declare function runRestore(options: RestoreOptions): Promise; /** * Restore from a URL */ declare function runRestoreFromUrl(url: string, options: RestoreOptions): Promise; /** * Restore from another postgres.do database */ declare function runRestoreFromDatabase(source: string, target: string, options: OutputOptions & { apiUrl?: string; clean?: boolean; }): Promise; /** * Logs Command * * View database logs from postgres.do * * @module cli/commands/logs */ /** * Logs command options */ interface LogsOptions extends OutputOptions { /** Database name or ID */ name: string; /** Tail logs (follow mode) */ tail?: boolean | undefined; /** Number of lines to show */ lines?: number | undefined; /** Show logs since timestamp or duration (e.g., "1h", "30m", "2024-01-15T10:00:00Z") */ since?: string | undefined; /** Show logs until timestamp */ until?: string | undefined; /** Filter by log level */ level?: 'debug' | 'info' | 'warning' | 'error' | undefined; /** Filter by search query */ query?: string | undefined; /** Show timestamps */ timestamps?: boolean | undefined; /** API URL override */ apiUrl?: string | undefined; } /** * Run logs command */ declare function runLogs(options: LogsOptions): Promise; /** * Get log statistics */ declare function runLogStats(name: string, options: OutputOptions & { apiUrl?: string; since?: string; until?: string; }): Promise; /** * Shell Command * * Interactive SQL REPL for postgres.do databases * * @module cli/commands/shell */ /** * Shell command options */ interface ShellOptions extends OutputOptions { /** Database name or ID */ name: string; /** Execute a single command and exit */ command?: string | undefined; /** Read commands from file */ file?: string | undefined; /** Enable timing output */ timing?: boolean | undefined; /** Output format for query results */ outputFormat?: 'table' | 'csv' | 'json' | 'aligned' | undefined; /** API URL override */ apiUrl?: string | undefined; } /** * Run shell command */ declare function runShell(options: ShellOptions): Promise; /** * postgres.do CLI * * Comprehensive CLI for postgres.do database management including: * - Database creation and management * - Schema introspection, generation, diff, and sync * - Migration management (run, status, rollback, create) * - Backup and restore * - Logs viewing * - Interactive SQL shell * * @example * ```bash * # Database management * postgres.do create mydb * postgres.do list * postgres.do delete mydb --force * * # Backup and restore * postgres.do backup mydb -o backup.sql * postgres.do restore backup.sql --database mydb * * # View logs * postgres.do logs mydb --tail * * # Interactive shell * postgres.do shell mydb * * # Schema commands * postgres.do introspect --url postgres://... --output ./schema.ts * postgres.do schema:diff --from $LOCAL_URL --to $PROD_URL * * # Migration commands * postgres.do migrate --url $DATABASE_URL * postgres.do migrate:status --url $DATABASE_URL * ``` * * @module cli */ declare const program: Command; export { program, runBackup, runBackupDownload, runBackupList, runCreate, runDelete, runDev, runDevReset, runImportPgDump, runInfo, runList, runLogStats, runLogs, runMigrate, runMigrateCreate, runMigrateDashboard, runMigrateDryRun, runMigrateFromNeon, runMigrateFromSupabase, runMigrateRollback, runMigrateStatus, runMigrateValidate, runMigrateValidateSchema, runQueryCompatibilityTest, runRestore, runRestoreFromDatabase, runRestoreFromUrl, runSchemaDiff, runSchemaPull, runSchemaPush, runShell };