Skip to content

Commit 408258f

Browse files
committed
feat: Enables logging to be passed in by facade user.
1 parent 95da305 commit 408258f

22 files changed

+147
-25
lines changed

src/FacadeConfig.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ import RepoFacade from './RepoFacade';
22

33
export default interface FacadeConfig {
44
readonly repo: RepoFacade;
5-
readonly log: (message: string) => void;
65
}

src/factory.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import factoryTest from './factoryTest';
66
import testRepoFactory from './utils/tests/testRepoFactory';
77

88
factoryTest((migrations) => {
9-
const log = () => null;
10-
return factory({ log, repo: testRepoFactory(migrations) });
9+
const repo = testRepoFactory(migrations);
10+
return factory({ repo });
1111
});

src/migrate/Signature.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import Status from '../utils/statuses/Status';
2+
13
export interface Opts {
24
readonly dryRun?: boolean;
5+
readonly log?: (status: Status) => void;
36
}
47

58
type Signature = (opts?: Opts) => Promise<void>;

src/migrate/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { reduce } from 'bluebird';
22
import FacadeConfig from '../FacadeConfig';
3+
import defaultLog from '../utils/defaultLog';
34
import getUnprocessedKeys from '../utils/getUnprocessedKeys';
45
import handleLocks from '../utils/handleLocks';
56
import migrateKey from '../utils/migrateKey';
67
import Signature, { Opts } from './Signature';
78

89
export default (config: FacadeConfig): Signature => {
9-
return async ({ dryRun = false }: Opts = {}) => {
10-
await handleLocks(config, async () => {
10+
return async ({ dryRun = false, log = defaultLog }: Opts = {}) => {
11+
await handleLocks({ config, log }, async () => {
1112
const unprocessedKeys = await getUnprocessedKeys(config);
1213
const batchStart = new Date();
1314

1415
await Promise.resolve(reduce(unprocessedKeys, async (_result, key) => {
15-
await migrateKey({ config, key, batchStart, dryRun });
16+
await migrateKey({ config, key, batchStart, dryRun, log });
1617
}, Promise.resolve()));
1718
});
1819
};

src/migrateByKey/Signature.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import Status from '../utils/statuses/Status';
2+
13
export interface Opts {
24
readonly key: string;
35
readonly force?: boolean;
46
readonly dryRun?: boolean;
7+
readonly log?: (status: Status) => void;
58
}
69

710
type Signature = (opts: Opts) => Promise<void>;

src/migrateByKey/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import FacadeConfig from '../FacadeConfig';
2+
import defaultLog from '../utils/defaultLog';
23
import ProcessedMigrationError from '../utils/errors/ProcessedMigrationError';
34
import handleLocks from '../utils/handleLocks';
45
import hasProcessedKey from '../utils/hasProcessedKey';
56
import migrateKey from '../utils/migrateKey';
67
import Signature from './Signature';
78

89
export default (config: FacadeConfig): Signature => {
9-
return async ({ key, force = false, dryRun = false }) => {
10-
await handleLocks(config, async () => {
10+
return async ({ key, force = false, dryRun = false, log = defaultLog }) => {
11+
await handleLocks({ config, log }, async () => {
1112
const isProcessed = await hasProcessedKey(config, key);
1213
if (isProcessed && !force) {
1314
throw new ProcessedMigrationError(key);
1415
}
1516

16-
await migrateKey({ config, key, dryRun });
17+
await migrateKey({ config, key, dryRun, log });
1718
});
1819
};
1920
};

src/rollback/Signature.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import Status from '../utils/statuses/Status';
2+
13
export interface Opts {
24
readonly dryRun?: boolean;
5+
readonly log?: (status: Status) => void;
36
}
47

58
type Signature = (opts?: Opts) => Promise<void>;

src/rollback/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import { reduce } from 'bluebird';
22
import FacadeConfig from '../FacadeConfig';
3+
import defaultLog from '../utils/defaultLog';
34
import getLastBatchKeys from '../utils/getLastBatchKeys';
45
import handleLocks from '../utils/handleLocks';
56
import rollbackKey from '../utils/rollbackKey';
67
import Signature, { Opts } from './Signature';
78

89
export default (config: FacadeConfig): Signature => {
9-
return async ({ dryRun = false }: Opts = {}) => {
10-
await handleLocks(config, async () => {
10+
return async ({ dryRun = false, log = defaultLog }: Opts = {}) => {
11+
await handleLocks({ config, log }, async () => {
1112
const lastBatchKeys = (await getLastBatchKeys(config)).reverse();
1213

1314
await Promise.resolve(reduce(lastBatchKeys, async (_result, key) => {
14-
await rollbackKey({ config, key, dryRun });
15+
await rollbackKey({ config, key, dryRun, log });
1516
}, Promise.resolve()));
1617
});
1718
};

src/rollbackByKey/Signature.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import Status from '../utils/statuses/Status';
2+
13
export interface Opts {
24
readonly key: string;
35
readonly force?: boolean;
46
readonly dryRun?: boolean;
7+
readonly log?: (status: Status) => void;
58
}
69

710
type Signature = (opts: Opts) => Promise<void>;

src/rollbackByKey/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import FacadeConfig from '../FacadeConfig';
2+
import defaultLog from '../utils/defaultLog';
23
import UnprocessedMigrationError from '../utils/errors/UnprocessedMigrationError';
34
import handleLocks from '../utils/handleLocks';
45
import hasProcessedKey from '../utils/hasProcessedKey';
56
import rollbackKey from '../utils/rollbackKey';
67
import Signature from './Signature';
78

89
export default (config: FacadeConfig): Signature => {
9-
return async ({ key, force = false, dryRun = false }) => {
10-
await handleLocks(config, async () => {
10+
return async ({ key, force = false, dryRun = false, log = defaultLog }) => {
11+
await handleLocks({ config, log }, async () => {
1112
const isProcessed = await hasProcessedKey(config, key);
1213
if (!isProcessed && !force) {
1314
throw new UnprocessedMigrationError(key);
1415
}
1516

16-
await rollbackKey({ config, key, dryRun });
17+
await rollbackKey({ config, key, dryRun, log });
1718
});
1819
};
1920
};

0 commit comments

Comments
 (0)