longcelot-sheet-db
Version:
Google Sheets-backed staging database adapter for Node.js with schema-first design
148 lines • 8.57 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
const commander_1 = require("commander");
const init_1 = require("./commands/init");
const generate_1 = require("./commands/generate");
const sync_1 = require("./commands/sync");
const validate_1 = require("./commands/validate");
const seed_1 = require("./commands/seed");
const mock_users_1 = require("./commands/mock-users");
const doctor_1 = require("./commands/doctor");
const status_1 = require("./commands/status");
const migrate_1 = require("./commands/migrate");
const migrate_data_1 = require("./commands/migrate-data");
const export_1 = require("./commands/export");
const export_data_1 = require("./commands/export-data");
const drop_table_1 = require("./commands/drop-table");
const drop_column_1 = require("./commands/drop-column");
const rename_column_1 = require("./commands/rename-column");
const erdiagram_1 = require("./commands/erdiagram");
const invokedAs = path_1.default.basename(process.argv[1] ?? '');
if (invokedAs === 'sheet-db') {
console.warn(chalk_1.default.yellow('⚠️ Deprecation: the `sheet-db` command is renamed to `lsdb`.\n' +
' Update your scripts to use `lsdb` — the old name will be removed in a future release.\n'));
}
const program = new commander_1.Command();
program
.name('lsdb')
.description('Google Sheets-backed staging database CLI')
.version('0.1.0');
program
.command('init')
.description('Initialize a new longcelot-sheet-db project')
.option('--integrate', 'Integrate into an existing project without overwriting configs')
.action(init_1.initCommand);
program
.command('generate <table-name>')
.description('Generate a new table schema')
.action(generate_1.generateCommand);
program
.command('sync')
.description('Sync schemas to Google Sheets')
.option('--all-users', 'Sync schema changes to all registered user sheets')
.option('--dry-run', 'Preview --all-users changes without applying them')
.option('--token-file <path>', 'Path to existing tokens JSON file (for CI/CD — skips interactive OAuth prompt)')
.action(sync_1.syncCommand);
program
.command('validate')
.description('Validate all schemas')
.action(validate_1.validateCommand);
program
.command('seed <seed-file>')
.description('Seed initial data into Google Sheets from a JS/TS file')
.option('--all-actors', 'Distribute seed data to all actor sheets (per users table)')
.option('--skip-existing', 'Skip rows where a unique column already matches (no error)')
.option('--upsert', 'Update existing row on unique conflict instead of throwing')
.action((seedFile, options) => (0, seed_1.seedCommand)(seedFile, {
allActors: options.allActors,
skipExisting: options.skipExisting,
upsert: options.upsert,
}));
program
.command('mock-users [count]')
.description('Create mock user sheets for development/testing')
.action((count) => (0, mock_users_1.mockUsersCommand)(count));
program
.command('doctor')
.description('Run diagnostics: check env vars, config, OAuth tokens, and schemas')
.action(doctor_1.doctorCommand);
program
.command('status')
.description('Show project status: tables, actors, sheet IDs, and token info')
.action(status_1.statusCommand);
program
.command('migrate')
.description('Export schemas to Prisma schema or SQL DDL')
.option('--prisma', 'Generate Prisma schema.prisma')
.option('--sql', 'Generate SQL DDL (CREATE TABLE statements)')
.option('--output <dir>', 'Output directory (default: current directory)')
.option('--apply', 'Apply the generated DDL to a live database (--sql), or run `prisma migrate deploy` (--prisma)')
.option('--connection-string <url>', 'Target DB connection string for --apply (falls back to $DATABASE_URL)')
.option('--driver <driver>', '--apply target driver: postgres|mysql (inferred from --connection-string if omitted)')
.option('--dry-run', 'Preview what --apply would do without executing it')
.action((options) => (0, migrate_1.migrateCommand)(options));
program
.command('migrate-data')
.description('Generate a data export script to move row data from Google Sheets to a production DB')
.option('--table <name>', 'Export a single table only')
.option('--all-users', 'Include all registered user sheets in addition to the admin sheet')
.option('--output <dir>', 'Output directory for migrate-data.js (default: current directory)')
.option('--dry-run', 'Preview export plan (or, with --run, row counts) without writing/migrating anything')
.option('--run', 'Run the cutover now, in-process, instead of generating a stub migrate-data.js')
.option('--connection-string <url>', 'Target DB connection string for --run (falls back to $DATABASE_URL)')
.option('--driver <driver>', '--run target driver: postgres|mysql (inferred from --connection-string if omitted)')
.option('--token-file <path>', 'Pre-stored OAuth tokens file for --run, skips interactive login (CI-friendly)')
.action((options) => (0, migrate_data_1.migrateDataCommand)({ ...options, allUsers: options.allUsers }));
program
.command('export')
.description('[deprecated] Use migrate instead. Exports schemas to Prisma schema or SQL DDL.')
.option('--prisma', 'Generate Prisma schema.prisma')
.option('--sql', 'Generate SQL DDL (CREATE TABLE statements)')
.option('--output <dir>', 'Output directory (default: current directory)')
.action((options) => (0, export_1.exportCommand)(options));
program
.command('export-data')
.description('[deprecated] Use migrate-data instead. Generates a data export script.')
.option('--table <name>', 'Export a single table only')
.option('--all-users', 'Include all registered user sheets in addition to the admin sheet')
.option('--output <dir>', 'Output directory (default: current directory)')
.option('--dry-run', 'Preview export plan without writing any files')
.action((options) => (0, export_data_1.exportDataCommand)({ ...options, allUsers: options.allUsers }));
program
.command('erdiagram')
.description('Generate a Mermaid ER diagram of table schemas and relationships as a Markdown file')
.option('--output <file>', 'Output file path (default: ER-DIAGRAM.md in project root)')
.option('--yes', 'Overwrite an existing output file without prompting')
.action((options) => (0, erdiagram_1.erdiagramCommand)(options));
program
.command('drop-table [table-names...]')
.description('Delete table schema file(s) and the corresponding Google Sheet tab(s)')
.option('--all-users', 'Also drop from every registered user sheet')
.option('--yes', 'Skip the confirmation prompt')
.option('--dry-run', 'Preview without making changes')
.option('--token-file <path>', 'Path to existing tokens JSON file (for CI/CD — skips interactive OAuth prompt)')
.action((tableNames, options) => (0, drop_table_1.dropTableCommand)(tableNames, options));
program
.command('drop-column [table-name] [column-names...]')
.description('Delete column(s) from a table schema file and the live Google Sheet')
.option('--all-users', 'Also drop from every registered user sheet')
.option('--yes', 'Skip the confirmation prompt')
.option('--dry-run', 'Preview without making changes')
.option('--token-file <path>', 'Path to existing tokens JSON file (for CI/CD — skips interactive OAuth prompt)')
.action((tableName, columnNames, options) => (0, drop_column_1.dropColumnCommand)(tableName, columnNames, options));
program
.command('rename-column [table-name] [old-name] [new-name]')
.description('Rename a column in a table schema file and the live Google Sheet header, preserving existing data')
.option('--all-users', 'Also rename on every registered user sheet')
.option('--yes', 'Skip the confirmation prompt')
.option('--dry-run', 'Preview without making changes')
.option('--token-file <path>', 'Path to existing tokens JSON file (for CI/CD — skips interactive OAuth prompt)')
.action((tableName, oldName, newName, options) => (0, rename_column_1.renameColumnCommand)(tableName, oldName, newName, options));
program.parse(process.argv);
//# sourceMappingURL=index.js.map