Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/guess-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ function guessModel(data, tablesOptions = {}, sequlizeInstance) {
fields[fieldName] = field;

// Make indexes based on column name
if (shouldIndex(columnName, tablesOptions)) {
if (shouldIndex(columnName, tablesOptions) && field.type != 'TEXT') {
// Index needs to use SQL name, not Sequelize name
modelOptions.indexes.push({ fields: [sqlName] });
// By default index name will be [table]_[fields]
modelOptions.indexes.push({ name: `ix_${sqlName}`, fields: [sqlName] });
}
});

Expand Down Expand Up @@ -142,8 +143,12 @@ function dataToType(data, name, tablesOptions = {}) {
else if (_.size(counted) === 1) {
kind = top.kind;
}
// If there is a string, use string
else if (counted.STRING) {
kind = 'STRING';
}
// If there is an integer and a float, use float
else if (counted.INTGER && counted.FLOAT) {
else if (counted.INTEGER && counted.FLOAT) {
kind = 'FLOAT';
}
else {
Expand Down Expand Up @@ -193,8 +198,8 @@ function shouldIndex(name, options = {}) {
// Find type. Should return base Sequelize type
function pickle(value, options = {}) {
// Tests
let floatTest = /^-?[\d,]+.\d+$/g;
let intTest = /^-?[\d,]+$/g;
let floatTest = /^[-+]?(\d{1,3}(,\d{3})*|\d+)\.\d+$/g;
let intTest = /^[-+]?(\d{1,3}(,\d{3})*|\d+)$/g;
let booleanTest = /^(true|false|y|n|yes|no)$/gi;
let dateTest = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/g;
let datetimeTest = /^\d{1,2}\/\d{1,2}\/\d{2,4}\s+\d{1,2}:\d{1,2}(:\d{1,2}|)(\s+|)(am|pm|)$/gi;
Expand Down