Skip to content

Commit 2992d2f

Browse files
committed
update docblocks, improve alter table method, code clean up
1 parent b9dcfe5 commit 2992d2f

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

shared/ezFunctions.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@
173173

174174
const ADD = 'ADD';
175175
const DROP = 'DROP COLUMN';
176-
const CHANGE = '__modifyColumn__';
176+
const CHANGE = 'CHANGE COLUMN';
177+
const ALTER = 'ALTER COLUMN';
178+
const MODIFY = 'MODIFY';
179+
const RENAME = 'RENAME TO';
180+
const CHANGER = '__modifyingColumns__';
177181

178182
const _DS = \DIRECTORY_SEPARATOR;
179183

shared/ezQuery.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ public function alter(string $table = null, ...$schemas)
760760
$skipSchema = false;
761761
if (\is_string($schemas[0])) {
762762
$data = '';
763-
$allowedTypes = ezSchema::CHANGES;
763+
$allowedTypes = ezSchema::ALTERS;
764764
$pattern = "/".\implode('|', $allowedTypes)."/i";
765765
foreach($schemas as $types) {
766766
if (\preg_match($pattern, $types)) {
@@ -788,9 +788,6 @@ public function drop(string $table = null)
788788

789789
$drop = 'DROP TABLE '.$table.';';
790790

791-
if (\is_string($drop))
792-
return $this->query($drop);
793-
794-
return false;
791+
return $this->query($drop);
795792
}
796793
}

shared/ezSchema.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ezSchema
5151
];
5252

5353
const OPTIONS = ['CONSTRAINT', 'PRIMARY KEY', 'FOREIGN KEY', 'UNIQUE', 'INDEX', 'REFERENCES'];
54+
const ALTERS = ['ADD', 'DROP COLUMN', 'CHANGE COLUMN', 'RENAME TO', 'MODIFY', 'ALTER COLUMN'];
5455
const CHANGES = [
5556
'mysql' => 'MODIFY',
5657
'postgresql' => 'ALTER COLUMN',
@@ -72,6 +73,16 @@ public function __construct( ...$args)
7273
$this->arguments = $args;
7374
}
7475

76+
/**
77+
* Makes an datatype callable from the above supported CONSTANTS.
78+
* This is used to create the database schema.
79+
*
80+
* @param string $type
81+
* @param array $args
82+
*
83+
* @return string
84+
* @throws Exception
85+
*/
7586
public function __call($type, $args)
7687
{
7788
$vendor = self::vendor();
@@ -199,7 +210,7 @@ public static function column(string $column = null, string $type = null, ...$ar
199210
$keyType = ($column != \INDEX) ? \array_shift($args).' ' : ' ';
200211
$keys = $keyType.'('.\to_string($args).'), ';
201212
$columnData .= $column.' '.$type.' '.$keys;
202-
} elseif (($column == \ADD) || ($column == \DROP) || ($column == \CHANGE)) {
213+
} elseif (($column == \ADD) || ($column == \DROP) || ($column == \CHANGER)) {
203214
if ($column != \DROP) {
204215
// check for modify placeholder and replace with vendors
205216
$column = \str_replace(\CHANGE, self::CHANGES[$vendor], $column);

0 commit comments

Comments
 (0)