Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
Fix "superClass not exists" error on multiple schemas
Browse files Browse the repository at this point in the history
**Breaking Change:** For better compability with `orientjs`, the
`parent` property in the `class` schema has been renamed to `superClass`
  • Loading branch information
dastoori committed Nov 10, 2017
1 parent 398415a commit 1873de4
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 50 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
An OrientDB development tools

<p align="center">
<a href="https://github.com/dastoori/orientx/releases"><img src="https://img.shields.io/github/release/dastoori/orientx.svg" alt="GitHub release" /></a>
<a href="https://www.npmjs.com/package/orientx"><img src="https://img.shields.io/npm/dm/orientx.svg" alt="NPM Downloads" /></a>
<a href="https://npmjs.com/package/orientx"><img src="https://img.shields.io/npm/v/orientx.svg" alt="npm version" /></a>
<a href="https://www.npmjs.com/package/orientx"><img src="https://img.shields.io/npm/dm/orientx.svg" alt="npm downloads" /></a>
<a href="https://raw.githubusercontent.com/dastoori/orientx/master/LICENSE.md"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="GitHub license" /></a></p>
</p>

Expand Down Expand Up @@ -159,7 +159,7 @@ $ orientx db:create ./schema.yaml
$ orientx dbc ./schema-*
```

or you can use [node-glob pattern](https://github.com/isaacs/node-glob#glob-primer) (you must use quotations)
or you can use [node-glob pattern](https://github.com/isaacs/node-glob#glob-primer) (it must have quotation marks)

```shell
$ orientx db:create './**/schema-@(db1|db2).{yaml,json}'
Expand Down Expand Up @@ -226,7 +226,7 @@ class:
User:
# https://orientdb.com/docs/last/SQL-Create-Class.html
name: User # [optional, autoPick]
parent: V # [optional]
superClass: V # [optional]
abstract: false # [optional]
cluster: 201,202 # [optional]

Expand Down Expand Up @@ -276,7 +276,7 @@ edge:

follow:
name: follow # [optional, autoPick]
parent: E # [optional, autoPick]
superClass: E # [optional, autoPick]

# Edge class properties (same as class properties)
props: # [optional]
Expand Down
24 changes: 23 additions & 1 deletion lib/db-create/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = exports = async (db, schema, title, filename) => {

return db.class.create(
className,
classSchema.parent,
null, // Set superClass later
classSchema.cluster,
classSchema.abstract
);
Expand All @@ -51,3 +51,25 @@ const getDbClassList = exports.getDbClassList = async (db, classSchema, refresh

return classList;
};

exports.superClass = async (db, schema, title, filename) => {
const result = await pMap(Object.keys(schema), async classKey => {
const classSchema = schema[classKey];

if (!classSchema.superClass) {
return undefined;
}

const className = classSchema.name || classKey;

return db.class.update({
name: className,
superClass: classSchema.superClass,
});
});

if (result.length && result[0]) {
Alert.success(`Setting "${db.name}" ${plur(title, 10)}${colors.hint(`\n at ${filename}`)}`);
}
};

6 changes: 3 additions & 3 deletions lib/db-create/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ module.exports = async (db, schema) => {
if (typeof edge === 'string') {
edge = schema.edge[edgeKey] = {
name: edgeKey,
parent: edge,
superClass: edge,
};
}

if (!edge.parent) {
edge.parent = 'E';
if (!edge.superClass) {
edge.superClass = 'E';
}
});

Expand Down
1 change: 1 addition & 0 deletions lib/db-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ async function createFromSchema(server, config, schema) {

return async () => {
// Dependent entities
await createClass.superClass(db, schema.class, 'super class', schema.__filename);
await createClassProps(db, schema.class, 'class property', schema.__filename);
await createEdge(db, schema);
await createIndex(db, schema);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"glob": "^7.1.2",
"js-yaml": "^3.10.0",
"lodash.flatten": "^4.4.0",
"mem": "^2.0.0",
"mem": "^3.0.0",
"migrate": "^1.0.0-2",
"minimist": "^1.2.0",
"npm-run-path": "^2.0.2",
Expand All @@ -37,7 +37,7 @@
"pkg-dir": "^2.0.0",
"plur": "^2.1.2",
"signal-exit": "^3.0.2",
"yup": "^0.22.0"
"yup": "^0.23.0"
},
"devDependencies": {
"eslint-config-afrasa": "^1.0.1"
Expand Down
87 changes: 48 additions & 39 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ acorn@^3.0.4, acorn@^3.1.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a"

acorn@^5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.1.2.tgz#911cb53e036807cf0fa778dc5d370fbd864246d7"
version "5.2.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.2.1.tgz#317ac7821826c22c702d66189ab8359675f135d7"

ajv-keywords@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.0.tgz#a296e17f7bfae7c1ce4f7e0de53d29cb32162df0"
version "2.1.1"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.1.tgz#617997fc5f60576894c435f940d819e135b80762"

ajv@^4.9.1:
version "4.11.8"
Expand All @@ -28,13 +28,13 @@ ajv@^4.9.1:
json-stable-stringify "^1.0.1"

ajv@^5.2.0, ajv@^5.2.3:
version "5.2.3"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.2.3.tgz#c06f598778c44c6b161abafe3466b81ad1814ed2"
version "5.3.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.3.0.tgz#4414ff74a50879c208ee5fdc826e32c303549eda"
dependencies:
co "^4.6.0"
fast-deep-equal "^1.0.0"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"
json-stable-stringify "^1.0.1"

ansi-escapes@^3.0.0:
version "3.0.0"
Expand Down Expand Up @@ -197,8 +197,8 @@ camel-case@^3.0.0:
upper-case "^1.1.1"

case@^1.2.1:
version "1.5.3"
resolved "https://registry.yarnpkg.com/case/-/case-1.5.3.tgz#b201631ac42e6e5b41b8baaf46f25006676e15c6"
version "1.5.4"
resolved "https://registry.yarnpkg.com/case/-/case-1.5.4.tgz#b201642aae9e374feb5750d1181a76850153830c"

caseless@~0.12.0:
version "0.12.0"
Expand All @@ -215,8 +215,8 @@ chalk@^1.1.3:
supports-color "^2.0.0"

chalk@^2.0.0, chalk@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.1.0.tgz#ac5becf14fa21b99c6c92ca7a7d7cfd5b17e743e"
version "2.3.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.3.0.tgz#b5ea48efc9c1793dccc9b4767c93914d3f2d52ba"
dependencies:
ansi-styles "^3.1.0"
escape-string-regexp "^1.0.5"
Expand Down Expand Up @@ -525,8 +525,8 @@ eslint-module-utils@^2.1.1:
pkg-dir "^1.0.0"

eslint-plugin-import@^2.6.1:
version "2.7.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.7.0.tgz#21de33380b9efb55f5ef6d2e210ec0e07e7fa69f"
version "2.8.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.8.0.tgz#fa1b6ef31fcb3c501c09859c1b86f1fc5b986894"
dependencies:
builtin-modules "^1.1.1"
contains-path "^0.1.0"
Expand All @@ -540,8 +540,8 @@ eslint-plugin-import@^2.6.1:
read-pkg-up "^2.0.0"

eslint-plugin-jasmine@^2.8.5:
version "2.8.5"
resolved "https://registry.yarnpkg.com/eslint-plugin-jasmine/-/eslint-plugin-jasmine-2.8.5.tgz#0e41d050fc31ca8a9a0f0ff56977fe42b3e7bc5c"
version "2.9.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-jasmine/-/eslint-plugin-jasmine-2.9.1.tgz#22e19a59f16f3a5f643a04aba04438d0e3047030"

eslint-plugin-json@^1.2.0:
version "1.2.0"
Expand Down Expand Up @@ -582,8 +582,8 @@ eslint-scope@^3.7.1:
estraverse "^4.1.1"

eslint@^4.3.0:
version "4.8.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.8.0.tgz#229ef0e354e0e61d837c7a80fdfba825e199815e"
version "4.10.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.10.0.tgz#f25d0d7955c81968c2309aa5c9a229e045176bb7"
dependencies:
ajv "^5.2.0"
babel-code-frame "^6.22.0"
Expand Down Expand Up @@ -679,6 +679,10 @@ fast-deep-equal@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff"

fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"

fast-levenshtein@~2.0.4:
version "2.0.6"
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
Expand Down Expand Up @@ -877,8 +881,8 @@ iconv-lite@^0.4.17, iconv-lite@~0.4.13:
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"

ignore@^3.3.3:
version "3.3.5"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.5.tgz#c4e715455f6073a8d7e5dae72d2fc9d71663dba6"
version "3.3.7"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021"

imurmurhash@^0.1.4:
version "0.1.4"
Expand Down Expand Up @@ -915,8 +919,8 @@ inquirer@^3.0.6:
through "^2.3.6"

irregular-plurals@^1.0.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/irregular-plurals/-/irregular-plurals-1.3.0.tgz#7af06931bdf74be33dcf585a13e06fccc16caecf"
version "1.4.0"
resolved "https://registry.yarnpkg.com/irregular-plurals/-/irregular-plurals-1.4.0.tgz#2ca9b033651111855412f16be5d77c62a458a766"

is-accessor-descriptor@^0.1.6:
version "0.1.6"
Expand All @@ -929,8 +933,8 @@ is-arrayish@^0.2.1:
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"

is-buffer@^1.1.5:
version "1.1.5"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc"
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"

is-builtin-module@^1.0.0:
version "1.0.0"
Expand Down Expand Up @@ -1047,8 +1051,8 @@ jsbn@~0.1.0:
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"

jschardet@^1.4.2:
version "1.5.1"
resolved "https://registry.yarnpkg.com/jschardet/-/jschardet-1.5.1.tgz#c519f629f86b3a5bedba58a88d311309eec097f9"
version "1.6.0"
resolved "https://registry.yarnpkg.com/jschardet/-/jschardet-1.6.0.tgz#c7d1a71edcff2839db2f9ec30fc5d5ebd3c1a678"

jshint@^2.8.0:
version "2.9.5"
Expand Down Expand Up @@ -1117,8 +1121,8 @@ kind-of@^3.0.2:
is-buffer "^1.1.5"

kind-of@^5.0.0:
version "5.0.2"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-5.0.2.tgz#f57bec933d9a2209ffa96c5c08343607b7035fda"
version "5.1.0"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-5.1.0.tgz#729c91e2d857b7a419a1f9aa65685c4c33f5845d"

levn@^0.3.0, levn@~0.3.0:
version "0.3.0"
Expand Down Expand Up @@ -1180,9 +1184,9 @@ lru-cache@^4.0.1:
pseudomap "^1.0.2"
yallist "^2.1.2"

mem@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/mem/-/mem-2.0.0.tgz#37b692533f101bec274c81a76c7bf4cd57fda89f"
mem@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/mem/-/mem-3.0.0.tgz#84e58ad4dfbdf5d105b26b6548a398b2b3aa8a21"
dependencies:
mimic-fn "^1.0.0"
p-is-promise "^1.1.0"
Expand Down Expand Up @@ -1578,8 +1582,8 @@ resolve-from@^1.0.0:
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"

resolve@^1.2.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.4.0.tgz#a75be01c53da25d934a98ebd0e4c4a7312f92a86"
version "1.5.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.5.0.tgz#1f09acce796c9a762579f31b2c1cc4c3cddf9f36"
dependencies:
path-parse "^1.0.5"

Expand Down Expand Up @@ -1742,11 +1746,15 @@ supports-color@^2.0.0:
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"

supports-color@^4.0.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.4.0.tgz#883f7ddabc165142b2a61427f3352ded195d1a3e"
version "4.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.5.0.tgz#be7a0de484dec5c5cddf8b3d59125044912f635b"
dependencies:
has-flag "^2.0.0"

synchronous-promise@^1.0.18:
version "1.0.18"
resolved "https://registry.yarnpkg.com/synchronous-promise/-/synchronous-promise-1.0.18.tgz#936e8763e6554088cdcf78dc64f7473b972fcefc"

table@^4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/table/-/table-4.0.2.tgz#a33447375391e766ad34d3486e6e2aedc84d2e36"
Expand Down Expand Up @@ -1811,8 +1819,8 @@ typedarray@^0.0.6:
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

ua-parser-js@^0.7.9:
version "0.7.14"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.14.tgz#110d53fa4c3f326c121292bbeac904d2e03387ca"
version "0.7.17"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.17.tgz#e9ec5f9498b9ec910e7ae3ac626a805c4d09ecac"

"unicode@>= 0.3.1":
version "10.0.0"
Expand Down Expand Up @@ -1889,13 +1897,14 @@ yargs@~1.2.1:
dependencies:
minimist "^0.1.0"

yup@^0.22.0:
version "0.22.0"
resolved "https://registry.yarnpkg.com/yup/-/yup-0.22.0.tgz#d25e226fdf2508a8eea3ff1eac20c5e1bb488bc3"
yup@^0.23.0:
version "0.23.0"
resolved "https://registry.yarnpkg.com/yup/-/yup-0.23.0.tgz#5901e80bec60c65fcfe0267f382b8ab2b27aa168"
dependencies:
case "^1.2.1"
fn-name "~1.0.1"
lodash "^4.17.0"
property-expr "^1.2.0"
synchronous-promise "^1.0.18"
toposort "^0.2.10"
type-name "^2.0.1"

0 comments on commit 1873de4

Please sign in to comment.