From dbda4be85365a3969d40c3670b31d7f5492ab94f Mon Sep 17 00:00:00 2001 From: Amy Faith Ho <82129885+amyfaithho@users.noreply.github.com> Date: Sun, 24 Jul 2022 13:18:24 -0500 Subject: [PATCH 1/6] Fix naming scheme for indexes to avoid conflicts - Prefer STRING if one is found in the column (see: https://github.com/zzolo/tables/pull/4/files) - Fix misspelled counted key for INTEGER (see: https://github.com/zzolo/tables/pull/3/files) - Fix naming scheme for indexes to avoid conflicts (appends table name) --- lib/guess-model.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/guess-model.js b/lib/guess-model.js index e1730bc..783cd2f 100644 --- a/lib/guess-model.js +++ b/lib/guess-model.js @@ -70,7 +70,8 @@ function guessModel(data, tablesOptions = {}, sequlizeInstance) { // Make indexes based on column name if (shouldIndex(columnName, tablesOptions)) { // 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] }); } }); @@ -142,8 +143,11 @@ function dataToType(data, name, tablesOptions = {}) { else if (_.size(counted) === 1) { kind = top.kind; } + 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 { From 93bb3c16bacaa77f79adfc483bf84136e0f1c533 Mon Sep 17 00:00:00 2001 From: Amy Faith Ho <82129885+amyfaithho@users.noreply.github.com> Date: Fri, 12 Aug 2022 12:55:08 -0500 Subject: [PATCH 2/6] fix regex definition for floatTest --- lib/guess-model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/guess-model.js b/lib/guess-model.js index 783cd2f..c07e492 100644 --- a/lib/guess-model.js +++ b/lib/guess-model.js @@ -197,7 +197,7 @@ function shouldIndex(name, options = {}) { // Find type. Should return base Sequelize type function pickle(value, options = {}) { // Tests - let floatTest = /^-?[\d,]+.\d+$/g; + let floatTest = /^-?[\d,]+\.\d+$/g; let intTest = /^-?[\d,]+$/g; let booleanTest = /^(true|false|y|n|yes|no)$/gi; let dateTest = /^\d{1,2}\/\d{1,2}\/\d{2,4}$/g; From b929ecdddce3523eb8a13db11129c158eada93fd Mon Sep 17 00:00:00 2001 From: Amy Faith Ho <82129885+amyfaithho@users.noreply.github.com> Date: Fri, 12 Aug 2022 13:11:06 -0500 Subject: [PATCH 3/6] improved definition for float and int in regex --- lib/guess-model.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/guess-model.js b/lib/guess-model.js index c07e492..781e00a 100644 --- a/lib/guess-model.js +++ b/lib/guess-model.js @@ -197,8 +197,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; From 0a85403f2e5b7cbc36ba54e8e1cc2f2c8cd470bf Mon Sep 17 00:00:00 2001 From: Anton Avramov Date: Sat, 20 Jul 2019 11:15:07 -0400 Subject: [PATCH 4/6] Fix mispelled counted key for INTEGER From af020ce7988a8d3ee88e14bd19b4ec71217c0fb3 Mon Sep 17 00:00:00 2001 From: Anton Avramov Date: Sat, 20 Jul 2019 11:16:17 -0400 Subject: [PATCH 5/6] Update to prefer STRING if one is found in the column --- lib/guess-model.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/guess-model.js b/lib/guess-model.js index 781e00a..4ce4ebc 100644 --- a/lib/guess-model.js +++ b/lib/guess-model.js @@ -143,6 +143,7 @@ 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'; } From 97c0211b2fc36442abecf054dec24cf808c86eff Mon Sep 17 00:00:00 2001 From: Anton Avramov Date: Sat, 20 Jul 2019 16:53:55 -0400 Subject: [PATCH 6/6] Do not index TEXT --- lib/guess-model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/guess-model.js b/lib/guess-model.js index 4ce4ebc..05a4d8e 100644 --- a/lib/guess-model.js +++ b/lib/guess-model.js @@ -68,7 +68,7 @@ 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 // By default index name will be [table]_[fields] modelOptions.indexes.push({ name: `ix_${sqlName}`, fields: [sqlName] });