/** * Create a table based on the entity ini conf file * * @return bool True if the table is created else false */ private function createTable() : bool { $columns = array(); $comment = 'AUTO GENERATED THE ' . date('Y-m-d H:i:s'); $sql = 'CREATE TABLE `' . $this->entity->getTableName() . '` ('; foreach ($this->entity->getColumnsAttributes() as $columnName => $columnAttributes) { $columns[] = $this->createColumnDefinition($columnName, $columnAttributes); } $sql .= implode(', ', $columns); $sql .= $this->createTableConstraints() . PHP_EOL; $sql .= ') ENGINE = ' . $this->entity->getEngine(); if ($this->entity->getCharset() !== '') { $sql .= ', CHARACTER SET = ' . $this->entity->getCharset(); } if ($this->entity->getCollation() !== '') { $sql .= ', COLLATE = ' . $this->entity->getCollation(); } if ($this->entity->getComment() !== '') { $comment .= ' | ' . $this->entity->getComment(); } $sql .= ', COMMENT = \'' . $comment . '\''; return DB::exec($sql . ';') !== false; }