Skip to content

Commit

Permalink
Merge pull request #4 from zishone/dev
Browse files Browse the repository at this point in the history
Bug Fixes and TravisCI Integration
  • Loading branch information
zishone committed Aug 3, 2019
2 parents f04edf0 + 407fbe0 commit 82ed473
Show file tree
Hide file tree
Showing 21 changed files with 142 additions and 114 deletions.
5 changes: 0 additions & 5 deletions .npmignore

This file was deleted.

33 changes: 28 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
language : node_js
node_js :
- stable
script:
- npm run ci
language: node_js
node_js:
- stable
install:
- npm ci
before_script:
- npm run cleanup
script:
- npm run build
- npm run docs
- npm run test:coverage
after_success:
- npm run test:coveralls
deploy:
- provider: pages
skip_cleanup: true
local_dir: docs
github_token: $GITHUB_TOKEN
on:
tags: true
branch: master
- provider: npm
skip_cleanup: true
email: "zishgarces@gmail.com"
api_key: $NPM_TOKEN
on:
tags: true
branch: master
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A MongoDB Database Server Seeder and Migration Tool.

## Introduction
`mongover` is a set of tools that allows specifying MongoDB Schema via a json format and apply it to the MongoDB Server(s) making MongoDB Database Versioning, Seeding, and Migration convenient.
`mongover` is a set of tools that can be used as a module dependency for NodeJS applications or as a command line interface tool for the purpose of seeding and migrating MongoDB databases.

## API
### Installation
Expand Down Expand Up @@ -124,7 +124,7 @@ $ mongover <command> [<args>] [<options>]
└── ...
* **db.spec.json**
```json
```json5
{
"seedOnly": false, // Specifies if existing database should be migrated or only seeded.
"dropFirst": false, // Specifies if existing database should be dropped before specification is applied.
Expand All @@ -133,7 +133,7 @@ $ mongover <command> [<args>] [<options>]
```
* **collectionName.spec.json**
```json
```json5
{
"dropFirst": false, // Specifies if the Collection should be dropped before specification is applied.
"dropIndexesFirst": false, // Specifies if all the Indexes of the Collection should be dropped before specification is applied.
Expand Down Expand Up @@ -172,7 +172,7 @@ $ mongover <command> [<args>] [<options>]
└── ...
* **db.spec.json**
```json
```json5
{
"seedOnly": false, // Specifies if existing database should be migrated or only seeded.
"dropFirst": false, // Specifies if existing database should be dropped before specification is applied.
Expand Down Expand Up @@ -207,7 +207,7 @@ $ mongover <command> [<args>] [<options>]
## Data Export File
* **jsonl**
```jsonl
```json
{"_id":{"$oid":"aaaaaaaaaaaaaaaaaaaaaaaa"},"fieldName": 1}
```
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 34 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,34 @@
{
"name": "mongover",
"version": "1.0.0-beta.2",
"version": "1.0.0-beta.3",
"description": "A MongoDB Server Database Migration Tool",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
"mongover": "dist/cli/index.js"
},
"files": [
"dist"
],
"scripts": {
"cleanup": "rimraf dist && rimraf coverage && rimraf .nyc_output && rimraf docs",
"lint": "tslint --project \"./tsconfig.json\"",
"lint": "tslint --project tsconfig.json",
"build": "tsc",
"build:watch": "tsc --watch",
"docs": "typedoc --out ./docs --mode modules --tsconfig ./tsconfig.json ./src/",
"gh-pages": "gh-pages -d docs",
"test": "mocha -r ts-node/register ./test/**/*.test.ts",
"coverage": "nyc --reporter=lcov --all npm run test",
"coveralls": "cat coverage/lcov.info | node_modules/coveralls/bin/coveralls.js",
"ci": "npm run cleanup && npm install && npm run lint && npm run build && npm run docs && npm run coverage"
},
"bin": {
"mongover": "dist/cli/index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/zishone/mongover.git"
"docs": "typedoc --out docs --mode modules --tsconfig tsconfig.json src && touch docs/.nojekyll",
"docs:deploy": "npm run docs && gh-pages --dotfiles --dist docs",
"test": "mocha --require ts-node/register test/**/*.test.ts",
"test:coverage": "nyc --reporter=lcov --include dist npm run test",
"test:coveralls": "cat coverage/lcov.info | coveralls",
"prepublish": "npm run build"
},
"author": "Zishran Julbert Garces <zishgarces@gmail.com> (https://github.com/zishone)",
"license": "MIT",
"bugs": {
"url": "https://github.com/zishone/mongover/issues"
},
"homepage": "https://github.com/zishone/mongover#readme",
"dependencies": {
"debug": "^4.1.1",
"fs-extra": "^8.1.0",
"minimist": "^1.2.0",
"mongodb": "^3.2.1",
"mongodb-extended-json": "^1.10.1"
},
"keywords": [
"mongover",
"mongodb",
"migration",
"versioning",
"database",
"seed",
"seeding"
],
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/debug": "^4.1.4",
Expand All @@ -63,5 +47,24 @@
"tslint": "^5.18.0",
"typedoc": "^0.15.0",
"typescript": "^3.5.3"
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/zishone/mongover.git"
},
"author": "Zishran Julbert Garces <zishgarces@gmail.com> (https://github.com/zishone)",
"license": "MIT",
"bugs": {
"url": "https://github.com/zishone/mongover/issues"
},
"homepage": "https://zishone.github.io/mongover/",
"keywords": [
"mongover",
"mongodb",
"migration",
"versioning",
"database",
"seed",
"seeding"
]
}
2 changes: 1 addition & 1 deletion src/cli/commands/apply.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { apply as coreApply } from '../../core/apply';
import { MongoverOptions } from '../../types/types';
import { getLogger } from '../../utils/get-logger';
import { MongoverOptions } from '../../utils/parse-options';

const logger = getLogger(__filename);

Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {
writeJSONSync,
} from 'fs-extra';
import { join } from 'path';
import { MongoverOptions } from '../../types/types';
import { connectServer } from '../../utils/connect-server';
import {
collectionSpecTemplate,
databaseSpecTemplate,
} from '../../utils/constants';
import { exportData } from '../../utils/export-data';
import { getLogger } from '../../utils/get-logger';
import { MongoverOptions } from '../../utils/parse-options';

const logger = getLogger(__filename);

Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
writeJSONSync,
} from 'fs-extra';
import { join } from 'path';
import { MongoverOptions } from '../../types/types';
import {
collectionSpecTemplate,
databaseSpecTemplate,
dataSample,
} from '../../utils/constants';
import { getLogger } from '../../utils/get-logger';
import { MongoverOptions } from '../../utils/parse-options';

const logger = getLogger(__filename);

Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env node

import debug = require('debug');
import * as minimist from 'minimist';
import minimist = require('minimist');
import { exit, usage } from '../utils/constants';
import { parseOptions } from '../utils/parse-options';
import { apply } from './commands/apply';
Expand Down
3 changes: 2 additions & 1 deletion src/core/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import {
readdirSync,
} from 'fs-extra';
import { join } from 'path';
import { MongoverOptions } from '../types/types';
import { buildIndex } from '../utils/build-index';
import { connectServer } from '../utils/connect-server';
import { createCollection } from '../utils/create-collection';
import { getLogger } from '../utils/get-logger';
import { getSpec } from '../utils/get-spec';
import { importData } from '../utils/import-data';
import { MongoverOptions, parseOptions } from '../utils/parse-options';
import { parseOptions } from '../utils/parse-options';
import { structureDatabase } from '../utils/structure-database';

const logger = getLogger(__filename);
Expand Down
52 changes: 52 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {
CollectionCreateOptions,
IndexOptions,
} from 'mongodb';

export interface IndexSpec {
keys: object;
options: IndexOptions;
dropFirst: boolean;
}

export interface CollectionSpec {
options: CollectionCreateOptions;
dropIndexesFirst: boolean;
dropFirst: boolean;
}

export interface DataSpec {
upsertFields: string[];
ignoreFields: string[];
preservePrimaryKey: boolean;
}

export interface MongoverOptions {
_: string[];
specPath: string;
u: string;
uri: string;
d: string;
dbs: string[];
c: string;
collections: string[];
a: string;
alias: string[];
e: string;
export: string;
f: string;
format: string;
t: string;
type: string;
q: string;
query: any;
s: boolean;
seedOnly: boolean;
}

export interface DatabaseSpec {
seedOnly: boolean;
dropFirst: boolean;
alias: string | undefined;
collections: any;
}
12 changes: 2 additions & 10 deletions src/utils/build-index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import {
Collection,
IndexOptions,
} from 'mongodb';
import { Collection } from 'mongodb';
import { IndexSpec } from '../types/types';
import { getLogger } from './get-logger';

const logger = getLogger(__filename);

interface IndexSpec {
keys: object;
options: IndexOptions;
dropFirst: boolean;
}

export async function buildIndex(collection: Collection, indexSpec: IndexSpec): Promise<void> {
const indexName = indexSpec.options.name || JSON.stringify(indexSpec.keys).replace(/[:,]/g, '_').replace(/[{}"]/g, '');
try {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DatabaseSpec } from './structure-database';
import { DatabaseSpec } from '../types/types';

export const usage = `
Usage:
Expand Down
8 changes: 1 addition & 7 deletions src/utils/create-collection.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import {
Collection,
CollectionCreateOptions,
Db,
} from 'mongodb';
import { CollectionSpec } from '../types/types';
import { getLogger } from './get-logger';

const logger = getLogger(__filename);

interface CollectionSpec {
options: CollectionCreateOptions;
dropIndexesFirst: boolean;
dropFirst: boolean;
}

export async function createCollection(db: Db, collectionName: string, collectionSpec: CollectionSpec, existingCollection: any): Promise<Collection> {
try {
logger.debug('Creating Collection: %s', collectionName);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/export-data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { appendFileSync } from 'fs';
import { writeJSONSync } from 'fs-extra';
import { Collection } from 'mongodb';
import * as EJSON from 'mongodb-extended-json';
import EJSON = require('mongodb-extended-json');
import { getLogger } from './get-logger';

const logger = getLogger(__filename);
Expand Down
5 changes: 4 additions & 1 deletion src/utils/get-logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { debug, Debugger } from 'debug';
import {
debug,
Debugger,
} from 'debug';

interface Logger {
debug: Debugger;
Expand Down
4 changes: 1 addition & 3 deletions src/utils/get-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export function getSpec(specPath: string) {
if (!spec.collections && existsSync(join(specPath, 'collections'))) {
spec.collections = {};
const collectionSpecsDir = join(specPath, 'collections');
const collectionSpecs = readdirSync(collectionSpecsDir, { withFileTypes: true })
.filter((dirent) => !dirent.isDirectory())
.map((dirent) => dirent.name);
const collectionSpecs = readdirSync(collectionSpecsDir).filter((dirent) => !lstatSync(join(collectionSpecsDir, dirent)).isDirectory());
for (const collectionSpec of collectionSpecs) {
spec.collections[collectionSpec.split('.')[0]] = readJSONSync(join(collectionSpecsDir, collectionSpec));
}
Expand Down
Loading

0 comments on commit 82ed473

Please sign in to comment.