json-schema-table
Advanced tools
Comparing version 0.0.2 to 0.0.3
12
index.js
@@ -248,2 +248,4 @@ var _ = require('lodash'); | ||
case 'text': | ||
column = 'NVARCHAR(MAX)'; | ||
break; | ||
case 'string': | ||
@@ -323,2 +325,4 @@ column = 'NVARCHAR(' + (property.maxLength ? property.maxLength : 'MAX') + ')'; | ||
case 'text': | ||
column = 'TEXT'; | ||
break; | ||
case 'string': | ||
@@ -467,7 +471,8 @@ if (property.maxLength) { | ||
is.decimals === void 0) || | ||
(was.type === 'datetime' && is.type === 'date'); | ||
(was.type === 'datetime' && is.type === 'date') || | ||
(was.type === 'text' && (is.type === 'string' && is.maxLength === void 0)); | ||
} | ||
function canAlterColumn(from, to) { | ||
return from.type === to.type && | ||
return (from.type === to.type && | ||
(from.type === 'string' && | ||
@@ -478,3 +483,4 @@ from.maxLength < to.maxLength) || | ||
from.decimals <= to.decimals && | ||
to.maxLength - from.maxLength >= to.decimals - from.decimals); | ||
to.maxLength - from.maxLength >= to.decimals - from.decimals)) || | ||
(from.type === 'string' && to.type === 'text'); | ||
} | ||
@@ -481,0 +487,0 @@ |
{ | ||
"name": "json-schema-table", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Creates and maintains a SQL table structure", | ||
@@ -5,0 +5,0 @@ "homepage": "", |
@@ -18,2 +18,5 @@ { | ||
}, | ||
"summary": { | ||
"type": "string" | ||
}, | ||
"description": { | ||
@@ -20,0 +23,0 @@ "type": "text" |
@@ -12,2 +12,3 @@ var jsonSchemaTable = require('..'); | ||
var modifiedClientSchema; | ||
var modifiedPersonSchema; | ||
var modifiedTaxSchema; | ||
@@ -31,2 +32,5 @@ | ||
expect(columns[columnName].maxLength).to.equal(undefined); | ||
} else if (property.type === 'string' && property.maxLength === void 0) { | ||
expect(columns[columnName].type === 'text').to.equal(true); | ||
expect(columns[columnName].maxLength).to.equal(undefined); | ||
} else if (property.type === 'object' || property.type === void 0) { | ||
@@ -311,3 +315,3 @@ //should be the type of the primary key of the referenced table | ||
it('should not alter person column dateOfBirth', function(done) { | ||
var modifiedPersonSchema = _.cloneDeep(personSchema); | ||
modifiedPersonSchema = _.cloneDeep(personSchema); | ||
modifiedPersonSchema.properties.dateOfBirth.type = 'string'; | ||
@@ -421,2 +425,21 @@ var person = jsonSchemaTable('person', modifiedPersonSchema, {db: db}); | ||
}); | ||
it('should alter person column name to text', function(done) { | ||
modifiedPersonSchema.properties.dateOfBirth.type = 'date'; | ||
modifiedPersonSchema.properties.name.type = 'text'; | ||
delete modifiedPersonSchema.properties.name.type; | ||
var person = jsonSchemaTable('person', modifiedPersonSchema, {db: db}); | ||
person.sync() | ||
.then(function() { | ||
return person.metadata() | ||
.then(function(metadata) { | ||
metadata.should.have.property('columns'); | ||
expect(metadata.columns).to.be.a('object'); | ||
checkColumns(metadata.columns, modifiedPersonSchema); | ||
done(); | ||
}); | ||
}) | ||
.catch(function(error) { | ||
done(error); | ||
}); | ||
}); | ||
}); | ||
@@ -426,2 +449,2 @@ | ||
} | ||
}; |
51183
1228