mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
Add types for mongration (#29843)
* Add types for mongration * Make MigrationResponse status type more explicit
This commit is contained in:
committed by
Sheetal Nandi
parent
5348b35343
commit
24a30d0f2e
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
// Type definitions for mongration 1.0
|
||||
// Project: https://github.com/awapps/mongration#readme
|
||||
// Definitions by: Anton Lobashev <https://github.com/soulthreads>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import { Db } from 'mongodb';
|
||||
|
||||
export interface DbConfig {
|
||||
hosts?: string;
|
||||
db?: string;
|
||||
user?: string;
|
||||
password?: string;
|
||||
mongoUri?: string;
|
||||
migrationCollection: string;
|
||||
replicaSet?: string;
|
||||
}
|
||||
|
||||
export interface MigrationResponse {
|
||||
id: string;
|
||||
status: 'not-run' | 'skipped' | 'pending' | 'ok' | 'error' | 'rollback' | 'rollback-error';
|
||||
}
|
||||
|
||||
export class Migration {
|
||||
constructor(dbConfig: DbConfig);
|
||||
add: (paths: string | string[]) => void;
|
||||
addAllFromPath: (path: string) => void;
|
||||
migrate: (doneCb?: (err: Error | null, response: MigrationResponse[]) => void) => void;
|
||||
}
|
||||
|
||||
export interface MigrationStep {
|
||||
id: string;
|
||||
up: (db: Db, cb: (err?: Error) => void) => void;
|
||||
down?: (db: Db, cb: (err?: Error) => void) => void;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Migration, DbConfig, MigrationStep } from 'mongration';
|
||||
|
||||
const dbConfig: DbConfig = {
|
||||
hosts: 'localhost:27017',
|
||||
db: 'testdb',
|
||||
migrationCollection: 'migrationversions'
|
||||
};
|
||||
|
||||
const migration = new Migration(dbConfig);
|
||||
migration.add('1-add-foo.js');
|
||||
migration.add(['2-add-bar.js', '3-add-foobar.js']);
|
||||
migration.addAllFromPath('migrations');
|
||||
migration.migrate((err, response) => {
|
||||
if (!err) {
|
||||
return response;
|
||||
}
|
||||
});
|
||||
|
||||
// from https://github.com/awapps/mongration#creating-migration-steps
|
||||
const step: MigrationStep = {
|
||||
id: '1-step',
|
||||
up: (db, cb) => {
|
||||
db.collection('testcolleciton').insert({ name: 'initial-setup' }, cb);
|
||||
},
|
||||
down: (db, cb) => {
|
||||
db.collection('testcollection').remove({ name: 'initial-setup' }, cb);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"mongration-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user