Skip to content

Commit 661527f

Browse files
committed
cleaner API
1 parent aef8926 commit 661527f

File tree

15 files changed

+64
-78
lines changed

15 files changed

+64
-78
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"permissions": {
33
"allow": [
4-
"Bash(rm:*)"
4+
"Bash(rm:*)",
5+
"Bash(mv:*)"
56
],
67
"deny": []
78
}

packages/cli/src/commands/deploy.ts

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import { CLIOptions, Inquirerer, Question } from 'inquirerer';
22
import { ParsedArgs } from 'minimist';
33

4-
import {
5-
getEnvOptions,
6-
LaunchQLOptions
7-
} from '@launchql/types';
8-
94
import {
105
getPgEnvOptions,
116
getSpawnEnvWithPg,
127
} from 'pg-env';
138

14-
import { deploy, deployWithOptions } from '@launchql/core';
9+
import { deployModules } from '@launchql/core';
1510
import { Logger } from '@launchql/logger';
1611
import { execSync } from 'child_process';
1712
import { getTargetDatabase } from '../utils';
@@ -83,34 +78,17 @@ export default async (
8378
log.info(`Selected project: ${projectName}`);
8479
}
8580

86-
// Handle fast deploy using the unified deploy function
87-
if (argv.fast && recursive) {
88-
const options: LaunchQLOptions = getEnvOptions({
89-
pg: {
90-
database
91-
}
92-
});
93-
94-
const { LaunchQLProject } = await import('@launchql/core');
95-
const project = new LaunchQLProject(cwd);
96-
const modules = project.getModuleMap();
97-
const modulePath = modules[projectName!].path;
98-
99-
await deploy(options, projectName!, database, modulePath, {
100-
fast: true,
101-
usePlan: true,
102-
cache: false
103-
});
104-
} else {
105-
await deployWithOptions({
106-
database,
107-
cwd,
108-
recursive,
109-
projectName,
110-
useSqitch,
111-
useTransaction: tx
112-
});
113-
}
81+
await deployModules({
82+
database,
83+
cwd,
84+
recursive,
85+
projectName,
86+
useSqitch,
87+
useTransaction: tx,
88+
fast: argv.fast,
89+
usePlan: argv.usePlan ?? true,
90+
cache: argv.cache ?? false
91+
});
11492

11593
log.success('Deployment complete.');
11694

packages/cli/src/commands/revert.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CLIOptions, Inquirerer, Question } from 'inquirerer';
22
import { Logger } from '@launchql/logger';
3-
import { revertWithOptions } from '@launchql/core';
3+
import { revertModules } from '@launchql/core';
44
import { getTargetDatabase } from '../utils';
55
import { selectModule } from '../utils/module-utils';
66

@@ -48,7 +48,7 @@ export default async (
4848
log.info(`Selected project: ${projectName}`);
4949
}
5050

51-
await revertWithOptions({
51+
await revertModules({
5252
database,
5353
cwd,
5454
recursive,

packages/cli/src/commands/verify.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CLIOptions, Inquirerer, Question } from 'inquirerer';
22
import { Logger } from '@launchql/logger';
3-
import { verifyWithOptions } from '@launchql/core';
3+
import { verifyModules } from '@launchql/core';
44
import { getTargetDatabase } from '../utils';
55
import { selectModule } from '../utils/module-utils';
66

@@ -27,7 +27,7 @@ export default async (
2727
log.info(`Selected project: ${projectName}`);
2828
}
2929

30-
await verifyWithOptions({
30+
await verifyModules({
3131
database,
3232
cwd,
3333
recursive,

packages/core/src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export * from './modules';
77
export * from './package';
88
export * from './paths';
99
export * from './resolve';
10-
export * from './sqitch/deploy';
11-
export * from './sqitch/revert';
12-
export * from './sqitch/verify';
10+
export * from './projects/deploy-project';
11+
export * from './projects/revert-project';
12+
export * from './projects/verify-project';
1313
export * from './transform';
1414
export * from './utils';
1515

1616
// New exports for migration API
17-
export * from './api/migration';
17+
export * from './migrate/migration';
1818
export { runSqitch } from './utils/sqitch-wrapper';
19-
export { deployCommand } from './migrate/deploy-command';
20-
export { revertCommand } from './migrate/revert-command';
21-
export { verifyCommand } from './migrate/verify-command';
19+
export { deployModule } from './migrate/deploy-module';
20+
export { revertModule } from './migrate/revert-module';
21+
export { verifyModule } from './migrate/verify-module';

packages/core/src/migrate/deploy-command.ts renamed to packages/core/src/migrate/deploy-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const log = new Logger('migrate-deploy');
1010
* Deploy command that mimics sqitch deploy behavior
1111
* This is designed to be a drop-in replacement for spawn('sqitch', ['deploy', 'db:pg:database'])
1212
*/
13-
export async function deployCommand(
13+
export async function deployModule(
1414
config: Partial<MigrateConfig>,
1515
database: string,
1616
cwd: string,
Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { LaunchQLProject } from '../class/launchql';
2-
import { deploy } from '../sqitch/deploy';
3-
import { revert } from '../sqitch/revert';
4-
import { verify } from '../sqitch/verify';
2+
import { deployProject } from '../projects/deploy-project';
3+
import { revertProject } from '../projects/revert-project';
4+
import { verifyProject } from '../projects/verify-project';
55
import { getEnvOptions } from '@launchql/types';
66
import { getPgEnvOptions } from 'pg-env';
77
import { Logger } from '@launchql/logger';
8-
import { deployCommand } from '../migrate/deploy-command';
9-
import { revertCommand } from '../migrate/revert-command';
10-
import { verifyCommand } from '../migrate/verify-command';
8+
import { deployModule } from './deploy-module';
9+
import { revertModule } from './revert-module';
10+
import { verifyModule } from './verify-module';
1111
import { runSqitch } from '../utils/sqitch-wrapper';
1212

1313
const log = new Logger('project-commands');
@@ -20,12 +20,16 @@ export interface MigrationOptions {
2020
useSqitch?: boolean;
2121
useTransaction?: boolean;
2222
toChange?: string;
23+
// Options for fast deployment
24+
fast?: boolean;
25+
usePlan?: boolean;
26+
cache?: boolean;
2327
}
2428

2529
/**
2630
* Deploy a project - handles both recursive (multi-module) and non-recursive (single directory) deployments
2731
*/
28-
export async function deployWithOptions(options: MigrationOptions): Promise<void> {
32+
export async function deployModules(options: MigrationOptions): Promise<void> {
2933
if (options.recursive) {
3034
if (!options.projectName) {
3135
throw new Error('projectName is required when recursive is true');
@@ -42,22 +46,25 @@ export async function deployWithOptions(options: MigrationOptions): Promise<void
4246
const modulePath = modules[options.projectName].path;
4347
log.info(`Deploying project ${options.projectName} from ${modulePath} to database ${options.database}...`);
4448

45-
await deploy(
49+
await deployProject(
4650
getEnvOptions({ pg: { database: options.database } }),
4751
options.projectName,
4852
options.database,
4953
modulePath,
5054
{
5155
useSqitch: options.useSqitch,
52-
useTransaction: options.useTransaction
56+
useTransaction: options.useTransaction,
57+
fast: options.fast,
58+
usePlan: options.usePlan,
59+
cache: options.cache
5360
}
5461
);
5562
} else {
5663
// Direct execution on current directory
5764
if (options.useSqitch) {
5865
await runSqitch('deploy', options.database, options.cwd);
5966
} else {
60-
await deployCommand(
67+
await deployModule(
6168
getPgEnvOptions(),
6269
options.database,
6370
options.cwd,
@@ -73,7 +80,7 @@ export async function deployWithOptions(options: MigrationOptions): Promise<void
7380
/**
7481
* Revert a project - handles both recursive (multi-module) and non-recursive (single directory) reverts
7582
*/
76-
export async function revertWithOptions(options: MigrationOptions): Promise<void> {
83+
export async function revertModules(options: MigrationOptions): Promise<void> {
7784
if (options.recursive) {
7885
if (!options.projectName) {
7986
throw new Error('projectName is required when recursive is true');
@@ -89,7 +96,7 @@ export async function revertWithOptions(options: MigrationOptions): Promise<void
8996

9097
log.info(`Reverting project ${options.projectName} on database ${options.database}...`);
9198

92-
await revert(
99+
await revertProject(
93100
getEnvOptions({ pg: { database: options.database } }),
94101
options.projectName,
95102
options.database,
@@ -104,7 +111,7 @@ export async function revertWithOptions(options: MigrationOptions): Promise<void
104111
if (options.useSqitch) {
105112
await runSqitch('revert', options.database, options.cwd);
106113
} else {
107-
await revertCommand(
114+
await revertModule(
108115
getPgEnvOptions(),
109116
options.database,
110117
options.cwd,
@@ -120,7 +127,7 @@ export async function revertWithOptions(options: MigrationOptions): Promise<void
120127
/**
121128
* Verify a project - handles both recursive (multi-module) and non-recursive (single directory) verification
122129
*/
123-
export async function verifyWithOptions(options: MigrationOptions): Promise<void> {
130+
export async function verifyModules(options: MigrationOptions): Promise<void> {
124131
if (options.recursive) {
125132
if (!options.projectName) {
126133
throw new Error('projectName is required when recursive is true');
@@ -136,7 +143,7 @@ export async function verifyWithOptions(options: MigrationOptions): Promise<void
136143

137144
log.info(`Verifying project ${options.projectName} on database ${options.database}...`);
138145

139-
await verify(
146+
await verifyProject(
140147
getEnvOptions({ pg: { database: options.database } }),
141148
options.projectName,
142149
options.database,
@@ -148,7 +155,7 @@ export async function verifyWithOptions(options: MigrationOptions): Promise<void
148155
if (options.useSqitch) {
149156
await runSqitch('verify', options.database, options.cwd);
150157
} else {
151-
await verifyCommand(
158+
await verifyModule(
152159
getPgEnvOptions(),
153160
options.database,
154161
options.cwd

packages/core/src/migrate/revert-command.ts renamed to packages/core/src/migrate/revert-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const log = new Logger('migrate-revert');
1010
* Revert command that mimics sqitch revert behavior
1111
* This is designed to be a drop-in replacement for spawn('sqitch', ['revert', 'db:pg:database'])
1212
*/
13-
export async function revertCommand(
13+
export async function revertModule(
1414
config: Partial<MigrateConfig>,
1515
database: string,
1616
cwd: string,

packages/core/src/migrate/verify-command.ts renamed to packages/core/src/migrate/verify-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const log = new Logger('migrate-verify');
1010
* Verify command that mimics sqitch verify behavior
1111
* This is designed to be a drop-in replacement for spawn('sqitch', ['verify', 'db:pg:database'])
1212
*/
13-
export async function verifyCommand(
13+
export async function verifyModule(
1414
config: Partial<MigrateConfig>,
1515
database: string,
1616
cwd: string

packages/core/src/sqitch/deploy.ts renamed to packages/core/src/projects/deploy-project.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { errors, LaunchQLOptions } from '@launchql/types';
55
import { getSpawnEnvWithPg, PgConfig } from 'pg-env';
66
import { Logger } from '@launchql/logger';
77
import { getPgPool } from 'pg-cache';
8-
import { deployCommand } from '../migrate/deploy-command';
8+
import { deployModule } from '../migrate/deploy-module';
99
import { LaunchQLProject } from '../class/launchql';
1010
import { packageModule } from '../package';
1111

@@ -28,7 +28,7 @@ const getCacheKey = (
2828

2929
const log = new Logger('deploy');
3030

31-
export const deploy = async (
31+
export const deployProject = async (
3232
opts: LaunchQLOptions,
3333
name: string,
3434
database: string,
@@ -155,7 +155,7 @@ export const deploy = async (
155155
log.debug(`→ Command: launchql migrate deploy db:pg:${database}`);
156156

157157
try {
158-
await deployCommand(opts.pg, database, modulePath, { useTransaction: options?.useTransaction });
158+
await deployModule(opts.pg, database, modulePath, { useTransaction: options?.useTransaction });
159159
} catch (deployError) {
160160
log.error(`❌ Deployment failed for module ${extension}`);
161161
throw errors.DEPLOYMENT_FAILED({ type: 'Deployment', module: extension });

0 commit comments

Comments
 (0)