* Create a table with given set of attributes * * ```js * queryInterface.createTable( * 'nameOfTheNewTable', * { * id: { * type: Sequelize.INTEGER, * primaryKey: true, * autoIncrement: true * }, * createdAt: { * type: Sequel
(tableName, attributes, options, model)
| 185 | * @returns {Promise} |
| 186 | */ |
| 187 | async createTable(tableName, attributes, options, model) { |
| 188 | let sql = class="st">''; |
| 189 | |
| 190 | options = { ...options }; |
| 191 | |
| 192 | if (options && options.uniqueKeys) { |
| 193 | _.forOwn(options.uniqueKeys, uniqueKey => { |
| 194 | if (uniqueKey.customIndex === undefined) { |
| 195 | uniqueKey.customIndex = true; |
| 196 | } |
| 197 | }); |
| 198 | } |
| 199 | |
| 200 | if (model) { |
| 201 | options.uniqueKeys = options.uniqueKeys || model.uniqueKeys; |
| 202 | } |
| 203 | |
| 204 | attributes = _.mapValues( |
| 205 | attributes, |
| 206 | attribute => this.sequelize.normalizeAttribute(attribute) |
| 207 | ); |
| 208 | |
| 209 | class="cm">// Postgres requires special SQL commands for ENUM/ENUM[] |
| 210 | await this.ensureEnums(tableName, attributes, options, model); |
| 211 | |
| 212 | if ( |
| 213 | !tableName.schema && |
| 214 | (options.schema || !!model && model._schema) |
| 215 | ) { |
| 216 | tableName = this.queryGenerator.addSchema({ |
| 217 | tableName, |
| 218 | _schema: !!model && model._schema || options.schema |
| 219 | }); |
| 220 | } |
| 221 | |
| 222 | attributes = this.queryGenerator.attributesToSQL(attributes, { table: tableName, context: class="st">'createTable' }); |
| 223 | sql = this.queryGenerator.createTableQuery(tableName, attributes, options); |
| 224 | |
| 225 | return await this.sequelize.query(sql, options); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Drop a table from database |
nothing calls this directly
no test coverage detected