| 73 | } |
| 74 | |
| 75 | async createTable(tableName, attributes, options, model) { |
| 76 | let sql = class="st">''; |
| 77 | |
| 78 | options = { ...options }; |
| 79 | |
| 80 | if (options && options.uniqueKeys) { |
| 81 | _.forOwn(options.uniqueKeys, uniqueKey => { |
| 82 | if (uniqueKey.customIndex === undefined) { |
| 83 | uniqueKey.customIndex = true; |
| 84 | } |
| 85 | }); |
| 86 | } |
| 87 | |
| 88 | if (model) { |
| 89 | options.uniqueKeys = options.uniqueKeys || model.uniqueKeys; |
| 90 | } |
| 91 | attributes = _.mapValues( |
| 92 | attributes, |
| 93 | attribute => this.sequelize.normalizeAttribute(attribute) |
| 94 | ); |
| 95 | if (options.indexes) { |
| 96 | options.indexes.forEach(fields=>{ |
| 97 | const fieldArr = fields.fields; |
| 98 | if (fieldArr.length === 1) { |
| 99 | fieldArr.forEach(field=>{ |
| 100 | for (const property in attributes) { |
| 101 | if (field === attributes[property].field) { |
| 102 | attributes[property].unique = true; |
| 103 | } |
| 104 | } |
| 105 | }); |
| 106 | } |
| 107 | }); |
| 108 | } |
| 109 | if (options.alter) { |
| 110 | if (options.indexes) { |
| 111 | options.indexes.forEach(fields=>{ |
| 112 | const fieldArr = fields.fields; |
| 113 | if (fieldArr.length === 1) { |
| 114 | fieldArr.forEach(field=>{ |
| 115 | for (const property in attributes) { |
| 116 | if (field === attributes[property].field && attributes[property].unique) { |
| 117 | attributes[property].unique = false; |
| 118 | } |
| 119 | } |
| 120 | }); |
| 121 | } |
| 122 | }); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | if ( |
| 127 | !tableName.schema && |
| 128 | (options.schema || !!model && model._schema) |
| 129 | ) { |
| 130 | tableName = this.queryGenerator.addSchema({ |
| 131 | tableName, |
| 132 | _schema: !!model && model._schema || options.schema |