42 $engine = $schema->engine;
44 $engine =
"ENGINE={$engine}";
47 $charset = $schema->charset;
49 $charset =
"DEFAULT CHARSET={$charset}";
53 foreach ($schema->
columns() as $column) {
54 $query[] = $column->toSql();
57 $query = array_filter($query);
58 $query = join(
', ' . PHP_EOL, $query);
60 $query =
"DROP TABLE IF EXISTS `{$name}`;" . PHP_EOL
61 .
"CREATE TABLE `{$name}` (" . PHP_EOL
63 .
") {$engine} {$charset}";
81 if ($schema->
isDirty(
'engine')) {
82 $props[] =
"ENGINE={$schema->engine}";
85 if ($schema->
isDirty(
'charset')) {
86 $props[] =
"DEFAULT CHARSET={$schema->charset}";
89 $props = array_filter($props);
90 $props = join(
', ' . PHP_EOL, $props);
95 if ($schema->
isDirty(ZendDbSchema_Db_Schema_Table::NAME_KEY)) {
97 if ($oldName && $oldName != $name) {
98 $query[] =
"RENAME TABLE `{$oldName}` TO `{$name}`";
102 $query[] =
"ALTER TABLE `{$name}` {$props}";
105 return join(
';' . PHP_EOL, $query);
119 return "DROP TABLE IF EXISTS {$schema->getOriginName()}";
132 $query[] = $schema->type .
"({$schema->length})";
135 $query[] =
"NOT NULL";
136 } elseif (null === $schema->default) {
138 $query[] =
"DEFAULT NULL";
141 if (null !== $schema->default) {
142 $query[] =
"DEFAULT {$schema->default}";
145 $query[] =
"COMMENT '{$schema->comment}'";
147 if (
false === $schema->
isSigned()) {
148 $query[] =
"UNSIGNED";
149 } elseif (
true === $schema->
isSigned()) {
153 if ($schema->autoincrement) {
154 $query[] =
"AUTO_INCREMENT";
157 if ($schema->after) {
158 $query[] =
"AFTER {$schema->after}";
161 return join(
' ', $query);
173 return "`{$name}`" .
' ' . $this->
_columnSql($schema);
190 $query[] =
"ALTER TABLE `{$schema->getTable()->getName()}`";
194 if ($oldName && $oldName != $name) {
196 $query[] =
"CHANGE `{$name}` `{$oldName}`";
198 $query[] =
"MODIFY `{$name}`";
201 $query[] =
"ADD `{$name}`";
204 return join(
' ', $query) .
' ' . $this->
_columnSql($schema);
216 $table = $schema->
getTable()->getName();
218 return "ALTER TABLE {$table} DROP COLUMN {$name}";
230 $table = $schema->
getTable()->getName();
234 $columns =
"(" . join(
', ', $schema->
getColumns()) .
")";
236 $type = strtoupper($schema->type);
242 $query[] =
"CREATE {$type} INDEX `{$name}` ON `{$table}` {$columns}";
244 return join(
';' . PHP_EOL, $query);
267 $table = $schema->
getTable()->getName();
269 $query =
"DROP INDEX IF EXISTS `{$name}` ON `{$table}`";
282 $table = $schema->
getTable()->getName();
284 $query =
"ALTER TABLE `{$table}` ADD PRIMARY KEY ({$columns})";
301 return join(
';' . PHP_EOL, $query);
312 $table = $schema->
getTable()->getName();
314 $query =
"ALTER TABLE `{$table}` DROP PRIMARY KEY";
329 $query[] =
"CONSTRAINT {$name}";
334 $refColumns = join(
'`,`', array_values($columns));
335 $columns = join(
'`,`', array_keys($columns));
338 $query[] =
" FOREIGN KEY (`{$columns}`) REFERENCES `{$refTable}` (`{$refColumns}`)";
341 $query[] =
" ON DELETE {$delete}";
344 $query[] =
" ON UPDATE {$update}";
347 $table = $schema->
getTable()->getName();
349 return "ALTER TABLE `{$table}` ADD " . join(
' ', $query);
365 return join(
';' . PHP_EOL, $query);
376 $table = $schema->
getTable()->getName();
379 $query =
"ALTER TABLE `{$table}` DROP FOREIGN KEY {$name}";