Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"permissions": {
"allow": [
"Bash(rm:*)",
"Bash(mv:*)"
],
"deny": []
}
}
87 changes: 18 additions & 69 deletions packages/cli/src/commands/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import { CLIOptions, Inquirerer, Question } from 'inquirerer';
import { ParsedArgs } from 'minimist';

import {
errors,
getEnvOptions,
LaunchQLOptions
} from '@launchql/types';
import {
getPgEnvOptions,
getSpawnEnvWithPg,
} from 'pg-env';

import { deploy, deployFast } from '@launchql/core';
import { deployModules } from '@launchql/core';
import { Logger } from '@launchql/logger';
import { execSync } from 'child_process';
import { LaunchQLProject } from '@launchql/core';
import { deployCommand } from '@launchql/migrate';
import { getTargetDatabase } from '../utils';
import { selectModule } from '../utils/module-utils';

export default async (
argv: Partial<ParsedArgs>,
Expand Down Expand Up @@ -71,77 +65,32 @@ export default async (

log.debug(`Using current directory: ${cwd}`);

const project = new LaunchQLProject(cwd);

if (createdb) {
log.info(`Creating database ${database}...`);
execSync(`createdb ${database}`, {
env: getSpawnEnvWithPg(pgEnv)
});
}

const options: LaunchQLOptions = getEnvOptions({
pg: {
database
}
});

let projectName: string | undefined;
if (recursive) {
const modules = await project.getModules();
const moduleNames = modules.map(mod => mod.getModuleName());

if (!moduleNames.length) {
log.error('No modules found in the specified directory.');
prompter.close();
throw errors.NOT_FOUND({}, 'No modules found in the specified directory.');
}

const { project: selectedProject } = await prompter.prompt(argv, [
{
type: 'autocomplete',
name: 'project',
message: 'Choose a project to deploy',
options: moduleNames,
required: true
}
]);

const selected = modules.find(mod => mod.getModuleName() === selectedProject);
if (!selected) {
throw new Error(`Module ${selectedProject} not found`);
}

const dir = selected.getModulePath()!;
log.success(`Deploying project ${selectedProject} from ${dir} to database ${database}...`);
projectName = await selectModule(argv, prompter, 'Choose a project to deploy', cwd);
log.info(`Selected project: ${projectName}`);
}

if (argv.fast) {
await deployFast({
opts: options,
database,
dir,
name: selectedProject,
usePlan: true,
cache: false
});
} else {
await deploy(options, selectedProject, database, dir, { useSqitch, useTransaction: tx });
}
await deployModules({
database,
cwd,
recursive,
projectName,
useSqitch,
useTransaction: tx,
fast: argv.fast,
usePlan: argv.usePlan ?? true,
cache: argv.cache ?? false
});

log.success('Deployment complete.');
} else {
if (useSqitch) {
log.info(`Running: sqitch deploy db:pg:${database} (using legacy Sqitch)`);
execSync(`sqitch deploy db:pg:${database}`, {
cwd,
env: getSpawnEnvWithPg(pgEnv),
stdio: 'inherit'
});
} else {
log.info(`Running: launchql migrate deploy db:pg:${database}`);
await deployCommand(pgEnv, database, cwd, { useTransaction: tx });
}
log.success('Deployment complete.');
}
log.success('Deployment complete.');

return argv;
};
63 changes: 15 additions & 48 deletions packages/cli/src/commands/revert.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { CLIOptions, Inquirerer, Question } from 'inquirerer';
import { LaunchQLProject, revert } from '@launchql/core';
import { errors, getEnvOptions, LaunchQLOptions } from '@launchql/types';
import { getPgEnvOptions, getSpawnEnvWithPg } from 'pg-env';
import { Logger } from '@launchql/logger';
import { revertCommand } from '@launchql/migrate';
import { execSync } from 'child_process';
import { revertModules } from '@launchql/core';
import { getTargetDatabase } from '../utils';
import { selectModule } from '../utils/module-utils';

const log = new Logger('revert');

Expand Down Expand Up @@ -45,52 +42,22 @@ export default async (

log.debug(`Using current directory: ${cwd}`);

const project = new LaunchQLProject(cwd);

let projectName: string | undefined;
if (recursive) {
const modules = await project.getModules();
const moduleNames = modules.map(mod => mod.getModuleName());

if (!moduleNames.length) {
log.error('No modules found in the specified directory.');
prompter.close();
throw errors.NOT_FOUND({}, 'No modules found in the specified directory.');
}

const { project: selectedProject } = await prompter.prompt(argv, [
{
type: 'autocomplete',
name: 'project',
message: 'Choose a project to revert',
options: moduleNames,
required: true
}
]);
projectName = await selectModule(argv, prompter, 'Choose a project to revert', cwd);
log.info(`Selected project: ${projectName}`);
}

log.success(`Reverting project ${selectedProject} on database ${database}...`);
const options: LaunchQLOptions = getEnvOptions({
pg: {
database
}
});
await revertModules({
database,
cwd,
recursive,
projectName,
useSqitch,
useTransaction: tx
});

await revert(options, selectedProject, database, cwd, { useSqitch, useTransaction: tx });
log.success('Revert complete.');
} else {
const pgEnv = getPgEnvOptions();
if (useSqitch) {
log.info(`Running: sqitch revert db:pg:${database} (using legacy Sqitch)`);
execSync(`sqitch revert db:pg:${database}`, {
cwd,
env: getSpawnEnvWithPg(pgEnv),
stdio: 'inherit'
});
} else {
log.info(`Running: launchql migrate revert db:pg:${database}`);
await revertCommand(pgEnv, database, cwd, { useTransaction: tx });
}
log.success('Revert complete.');
}
log.success('Revert complete.');

return argv;
};
62 changes: 14 additions & 48 deletions packages/cli/src/commands/verify.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { CLIOptions, Inquirerer, Question } from 'inquirerer';
import { LaunchQLProject, verify } from '@launchql/core';
import { errors, getEnvOptions, LaunchQLOptions } from '@launchql/types';
import { getPgEnvOptions, getSpawnEnvWithPg } from 'pg-env';
import { Logger } from '@launchql/logger';
import { verifyCommand } from '@launchql/migrate';
import { execSync } from 'child_process';
import { verifyModules } from '@launchql/core';
import { getTargetDatabase } from '../utils';
import { selectModule } from '../utils/module-utils';

const log = new Logger('verify');

Expand All @@ -24,52 +21,21 @@ export default async (

log.debug(`Using current directory: ${cwd}`);

const project = new LaunchQLProject(cwd);

let projectName: string | undefined;
if (recursive) {
const modules = await project.getModules();
const moduleNames = modules.map(mod => mod.getModuleName());

if (!moduleNames.length) {
log.error('No modules found in the specified directory.');
prompter.close();
throw errors.NOT_FOUND({}, 'No modules found in the specified directory.');
}

const { project: selectedProject } = await prompter.prompt(argv, [
{
type: 'autocomplete',
name: 'project',
message: 'Choose a project to verify',
options: moduleNames,
required: true
}
]);
projectName = await selectModule(argv, prompter, 'Choose a project to verify', cwd);
log.info(`Selected project: ${projectName}`);
}

const options: LaunchQLOptions = getEnvOptions({
pg: {
database
}
});
await verifyModules({
database,
cwd,
recursive,
projectName,
useSqitch
});

log.info(`Verifying project ${selectedProject} on database ${database}...`);
await verify(options, selectedProject, database, cwd, { useSqitch });
log.success('Verify complete.');
} else {
const pgEnv = getPgEnvOptions();
if (useSqitch) {
log.info(`Running: sqitch verify db:pg:${database} (using legacy Sqitch)`);
execSync(`sqitch verify db:pg:${database}`, {
cwd,
env: getSpawnEnvWithPg(pgEnv),
stdio: 'inherit'
});
} else {
log.info(`Running: launchql migrate verify db:pg:${database}`);
await verifyCommand(pgEnv, database, cwd);
}
log.success('Verify complete.');
}
log.success('Verify complete.');

return argv;
};
31 changes: 31 additions & 0 deletions packages/cli/src/utils/module-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Inquirerer } from 'inquirerer';
import { ParsedArgs } from 'minimist';
import { getAvailableModules } from '@launchql/core';
import { errors } from '@launchql/types';

/**
* Prompt user to select a module from available modules in the directory
*/
export async function selectModule(
argv: Partial<ParsedArgs>,
prompter: Inquirerer,
message: string,
cwd: string
): Promise<string> {
const modules = await getAvailableModules(cwd);

if (!modules.length) {
prompter.close();
throw errors.NOT_FOUND({}, 'No modules found in the specified directory.');
}

const { project } = await prompter.prompt(argv, [{
type: 'autocomplete',
name: 'project',
message,
options: modules,
required: true
}]);

return project;
}
Loading