@@ 32-57 (lines=26) @@ | ||
29 | * |
|
30 | * @return bool |
|
31 | */ |
|
32 | public function createTable(TableNodeInterface $table, array $columns) |
|
33 | { |
|
34 | $this->log(LogLevel::DEBUG, "Creating Table {table} with columns: {columns}", [ |
|
35 | 'table' => $table->getFullName(), |
|
36 | 'columns' => implode(',', array_keys($columns)), |
|
37 | ]); |
|
38 | ||
39 | $columnStrings = []; |
|
40 | $primary = []; |
|
41 | $indexes = []; |
|
42 | ||
43 | foreach ($columns as $column) { |
|
44 | $columnStrings[] = $this->dialect->getColumnDefinition($column); |
|
45 | if ($column['primary']) { |
|
46 | $primary[] = $this->dialect->getPrimaryKeyDefinition($column); |
|
47 | } elseif ($column['index']) { |
|
48 | $indexes[] = $this->dialect->getIndexDefinition($column); |
|
49 | } |
|
50 | } |
|
51 | ||
52 | list($sql, $params) = $this->dialect->getCreateTable($table, $columnStrings, $primary, $indexes); |
|
53 | $db = $table->getAdapter(); |
|
54 | $db->query(trim($sql), $params); |
|
55 | ||
56 | return true; |
|
57 | } |
|
58 | ||
59 | /** |
|
60 | * @param TableNodeInterface $table |
@@ 34-61 (lines=28) @@ | ||
31 | * |
|
32 | * @return bool |
|
33 | */ |
|
34 | public function createTable(TableNodeInterface $table, array $columns) |
|
35 | { |
|
36 | $this->log(LogLevel::INFO, "Creating Table {table} with columns: {columns}", [ |
|
37 | 'table' => $table->getFullName(), |
|
38 | 'columns' => implode(',', array_keys($columns)), |
|
39 | ]); |
|
40 | ||
41 | $dist = []; |
|
42 | $sorted = []; |
|
43 | $columnStrings = []; |
|
44 | ||
45 | foreach ($columns as $column) { |
|
46 | if ($column['primary'] && !$dist) { |
|
47 | $dist[] = $this->dialect->getPrimaryKeyDefinition($column); |
|
48 | } elseif ($column['primary'] || $column['index']) { |
|
49 | $sorted[] = $this->dialect->getIndexDefinition($column); |
|
50 | } |
|
51 | ||
52 | $columnStrings[] = $this->dialect->getColumnDefinition($column); |
|
53 | } |
|
54 | ||
55 | list ($sql, $params) = $this->dialect->getCreateTable($table, $columnStrings, $dist, $sorted); |
|
56 | ||
57 | $db = $table->getAdapter(); |
|
58 | $db->query(trim($sql), $params); |
|
59 | ||
60 | return true; |
|
61 | } |
|
62 | ||
63 | /** |
|
64 | * @param TableNodeInterface $table |