relational-schema
Advanced tools
Comparing version 0.4.3 to 0.4.4
@@ -41,2 +41,3 @@ #! /usr/bin/env node | ||
database: { type: 'string', default: 'public' }, | ||
schema: { type: 'string', default: 'public' }, | ||
outdir: { type: 'string', default: './gen' }, | ||
@@ -101,2 +102,3 @@ format: { choices: formats, default: "json" /* json */ }, | ||
database: args.database, | ||
schema: args.schema, | ||
}, | ||
@@ -117,2 +119,3 @@ }; | ||
logger_1.logger.error(e); | ||
logger_1.logger.debug(e.stack); | ||
logger_1.logger.info('Use: "relation -h" to see help'); | ||
@@ -119,0 +122,0 @@ process.exit(1); |
@@ -21,2 +21,3 @@ "use strict"; | ||
const table_schema_builder_1 = require("./table-schema-builder"); | ||
const logger_1 = require("../lib/logger"); | ||
/** | ||
@@ -51,12 +52,19 @@ * Build schema from database connection | ||
}; | ||
logger_1.logger.debug(`Introspecting ${JSON.stringify(relationalSchema)}`); | ||
try { | ||
const tables = yield DB.getSchemaTables(); | ||
logger_1.logger.debug(`Found ${tables.length} tables`); | ||
const enums = yield DB.getEnumTypesForTables(tables); | ||
logger_1.logger.debug(`Introspected ${Object.entries(enums).length} enums`); | ||
const definitions = yield DB.getTableTypes(tables, enums); | ||
logger_1.logger.debug(`Introspected ${Object.entries(definitions).length} tables`); | ||
const constraints = yield DB.getTableConstraints(tables); | ||
logger_1.logger.debug(`Introspected ${Object.entries(constraints).length} constraints`); | ||
const forward = yield DB.getForwardRelations(tables); | ||
const backwards = yield DB.getBackwardRelations(tables); | ||
logger_1.logger.debug(`Introspected ${Object.entries(forward).length + Object.entries(backwards).length} foreign key relations`); | ||
tables.forEach((table) => { | ||
relationalSchema.tables[table] = new table_schema_builder_1.TableSchemaBuilder(table, enums, definitions, constraints, forward, backwards).buildTableDefinition(options); | ||
}); | ||
logger_1.logger.debug(`Built ${Object.entries(relationalSchema.tables).length} table schemas`); | ||
yield knex.destroy(); | ||
@@ -63,0 +71,0 @@ } |
@@ -28,3 +28,3 @@ "use strict"; | ||
if (this.logLevel === types_1.LogLevel.debug) { | ||
logger_1.logger.debug('Executing query: ', query.toSQL()); | ||
logger_1.logger.debug('Executing query: ', query.toSQL().sql); | ||
} | ||
@@ -31,0 +31,0 @@ return yield query; |
@@ -129,6 +129,7 @@ "use strict"; | ||
tableBackwardRelations.forEach((backwardRelation) => { | ||
// get the other (forward) side of the relation to check cardinalityu | ||
var _a; | ||
// get the other (forward) side of the relation to check cardinality | ||
const keys = this.constraints[backwardRelation.toTable]; | ||
const [forwardRelation] = this.forwardRelations[backwardRelation.toTable].filter((r) => r.toTable === this.tableName); | ||
if (cardinality_resolver_1.CardinalityResolver.isOneToOneRelation({ forwardRelation, keys })) { | ||
const forwardRelation = (_a = this.forwardRelations[backwardRelation.toTable]) === null || _a === void 0 ? void 0 : _a.find((r) => r.toTable === this.tableName); | ||
if (forwardRelation && cardinality_resolver_1.CardinalityResolver.isOneToOneRelation({ forwardRelation, keys })) { | ||
uniqueRelations.push(backwardRelation); | ||
@@ -188,8 +189,8 @@ } | ||
buildTableDefinition(options) { | ||
var _a, _b; | ||
const tableConstraints = this.constraints[this.tableName]; | ||
var _a, _b, _c; | ||
const tableConstraints = (_a = this.constraints[this.tableName]) !== null && _a !== void 0 ? _a : []; | ||
const tableEnums = this.enums[this.tableName]; | ||
const tableColumns = this.tableDefinitions[this.tableName]; | ||
const tableForwardRelations = (_a = this.forwardRelations[this.tableName]) !== null && _a !== void 0 ? _a : []; | ||
const tableBackwardRelations = (_b = this.backwardRelations[this.tableName]) !== null && _b !== void 0 ? _b : []; | ||
const tableForwardRelations = (_b = this.forwardRelations[this.tableName]) !== null && _b !== void 0 ? _b : []; | ||
const tableBackwardRelations = (_c = this.backwardRelations[this.tableName]) !== null && _c !== void 0 ? _c : []; | ||
const tableUniqueRelations = this.getTableOneToOneRelationships(tableForwardRelations, tableBackwardRelations); | ||
@@ -196,0 +197,0 @@ let tableTransitiveRelations = []; |
@@ -0,1 +1,8 @@ | ||
## [0.4.4](https://github.com/MattGson/relational-schema/compare/v0.4.3...v0.4.4) (2021-09-27) | ||
### Bug Fixes | ||
* **introspect:** fixes crash on empty contraints list ([8c23049](https://github.com/MattGson/relational-schema/commit/8c23049220accd6727d559cdc23a22ae48aeeffe)) | ||
## [0.4.3](https://github.com/MattGson/relational-schema/compare/v0.4.2...v0.4.3) (2021-05-26) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "relational-schema", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Generate a js schema for a relational database", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
151169
1874