MCPcopy
hub / github.com/sequelize/sequelize / createTable

Method createTable

src/dialects/abstract/query-interface.js:187–230  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

185 * @returns {Promise}
186 */
187 async createTable(tableName, attributes, options, model) {
188 let sql = '';
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 // 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, {
223 table: tableName,
224 context: 'createTable',
225 withoutForeignKeyConstraints: options.withoutForeignKeyConstraints
226 });
227 sql = this.queryGenerator.createTableQuery(tableName, attributes, options);
228
229 return await this.sequelize.query(sql, options);
230 }
231
232 /**
233 * Returns a promise that will resolve to true if the table exists in the database, false otherwise.

Callers

nothing calls this directly

Calls 6

ensureEnumsMethod · 0.95
addSchemaMethod · 0.80
normalizeAttributeMethod · 0.45
attributesToSQLMethod · 0.45
createTableQueryMethod · 0.45
queryMethod · 0.45

Tested by

no test coverage detected