Skip to content

Commit 3b2b3a8

Browse files
Add test case for partial verification with toChange parameter
- Implement toChange parameter support in LaunchQLMigrate.verify method - Add logic to filter changes up to specified toChange point - Fix recursive verification to only apply toChange to target module - Add comprehensive test case demonstrating partial verification functionality - Test verifies that toChange limits verification scope and throws on failure Co-Authored-By: Dan Lynch <[email protected]>
1 parent 9e42864 commit 3b2b3a8

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { TestDatabase } from '../../test-utils';
2+
import { CoreDeployTestFixture } from '../../test-utils/CoreDeployTestFixture';
3+
4+
describe('Partial Verification with toChange parameter', () => {
5+
let fixture: CoreDeployTestFixture;
6+
let db: TestDatabase;
7+
8+
beforeEach(async () => {
9+
fixture = new CoreDeployTestFixture('sqitch', 'simple-w-tags');
10+
db = await fixture.setupTestDatabase();
11+
});
12+
13+
afterEach(async () => {
14+
await fixture.cleanup();
15+
});
16+
17+
test('verifies partial deployment with toChange parameter', async () => {
18+
await fixture.deployModule('my-third', db.name, ['sqitch', 'simple-w-tags']);
19+
await fixture.verifyModule('my-third', db.name, ['sqitch', 'simple-w-tags']);
20+
21+
const verifyScriptPath = fixture.fixturePath('packages', 'my-third', 'verify', 'create_table.sql');
22+
const fs = require('fs');
23+
const originalContent = fs.readFileSync(verifyScriptPath, 'utf8');
24+
25+
const brokenContent = originalContent.replace(
26+
"table_name = 'customers'",
27+
"table_name = 'nonexistent_table'"
28+
);
29+
fs.writeFileSync(verifyScriptPath, brokenContent);
30+
31+
await fixture.verifyModule('my-third', db.name, ['sqitch', 'simple-w-tags'], 'create_schema');
32+
33+
await expect(
34+
fixture.verifyModule('my-third', db.name, ['sqitch', 'simple-w-tags'])
35+
).rejects.toThrow();
36+
37+
fs.writeFileSync(verifyScriptPath, originalContent);
38+
});
39+
});

packages/core/src/core/class/launchql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ export class LaunchQLProject {
934934

935935
const result = await client.verify({
936936
modulePath,
937-
toChange
937+
toChange: extension === name ? toChange : undefined
938938
});
939939

940940
if (result.failed.length > 0) {

packages/core/src/migrate/client.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,18 @@ export class LaunchQLMigrate {
474474
async verify(options: VerifyOptions): Promise<VerifyResult> {
475475
await this.initialize();
476476

477-
const { modulePath } = options;
477+
const { modulePath, toChange } = options;
478478
const planPath = join(modulePath, 'launchql.plan');
479479
const plan = parsePlanFileSimple(planPath);
480-
const changes = getChangesInOrder(planPath);
480+
let changes = getChangesInOrder(planPath);
481+
482+
if (toChange) {
483+
const toChangeIndex = changes.findIndex(c => c.name === toChange);
484+
if (toChangeIndex === -1) {
485+
throw new Error(`Change '${toChange}' not found in plan`);
486+
}
487+
changes = changes.slice(0, toChangeIndex + 1);
488+
}
481489

482490
const verified: string[] = [];
483491
const failed: string[] = [];

0 commit comments

Comments
 (0)