From 7f13bdf0a7377ae00406a6a7de0a9101f5166fa7 Mon Sep 17 00:00:00 2001 From: smiPC Date: Mon, 22 Sep 2025 11:37:38 +0300 Subject: [PATCH 1/5] The operation of the "description" method when creating a table has been fixed. --- src/Schema/BaseColumn.php | 2 +- src/Schema/Compiler.php | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Schema/BaseColumn.php b/src/Schema/BaseColumn.php index 0ae20f8..0e57dea 100644 --- a/src/Schema/BaseColumn.php +++ b/src/Schema/BaseColumn.php @@ -132,7 +132,7 @@ public function notNull(): self */ public function description(string $comment): self { - return $this->set('description', $comment); + return $this->set('comment', $comment); } /** diff --git a/src/Schema/Compiler.php b/src/Schema/Compiler.php index 1fd4182..6a7882f 100644 --- a/src/Schema/Compiler.php +++ b/src/Schema/Compiler.php @@ -31,7 +31,7 @@ class Compiler protected $params = []; /** @var string[] */ - protected $modifiers = ['unsigned', 'nullable', 'default', 'autoincrement']; + protected $modifiers = ['unsigned', 'nullable', 'default', 'autoincrement', 'comment']; /** @var string[] */ protected $serials = ['tiny', 'small', 'normal', 'medium', 'big']; @@ -310,6 +310,15 @@ protected function handleModifierDefault(BaseColumn $column): string return null === $column->get('default') ? '' : 'DEFAULT ' . $this->value($column->get('default')); } + /** + * @param BaseColumn $column + * @return string + */ + protected function handleModifierComment(BaseColumn $column): string + { + return $column->get('comment') ? ' COMMENT \'' . $column->get('comment') . '\'' : ''; + } + /** * @param BaseColumn $column * @return string From 5de5c3e114cdd5e50a04ad293fc7862bf8e79889 Mon Sep 17 00:00:00 2001 From: smiPC Date: Mon, 22 Sep 2025 11:47:37 +0300 Subject: [PATCH 2/5] onUpdateCurrentTimeStamp method added --- src/Schema/BaseColumn.php | 8 ++++++++ src/Schema/Compiler.php | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Schema/BaseColumn.php b/src/Schema/BaseColumn.php index 0e57dea..9c8b2c5 100644 --- a/src/Schema/BaseColumn.php +++ b/src/Schema/BaseColumn.php @@ -135,6 +135,14 @@ public function description(string $comment): self return $this->set('comment', $comment); } + /** + * @return $this + */ + public function onUpdateCurrentTimeStamp(): self + { + return $this->set('onUpdateCurrentTimeStamp', 1); + } + /** * @param $value * @return $this diff --git a/src/Schema/Compiler.php b/src/Schema/Compiler.php index 6a7882f..409fcdf 100644 --- a/src/Schema/Compiler.php +++ b/src/Schema/Compiler.php @@ -31,7 +31,7 @@ class Compiler protected $params = []; /** @var string[] */ - protected $modifiers = ['unsigned', 'nullable', 'default', 'autoincrement', 'comment']; + protected $modifiers = ['unsigned', 'nullable', 'default', 'autoincrement', 'comment', 'onUpdateCurrentTimeStamp']; /** @var string[] */ protected $serials = ['tiny', 'small', 'normal', 'medium', 'big']; @@ -258,7 +258,7 @@ protected function handleTypeTime(BaseColumn $column): string */ protected function handleTypeTimestamp(BaseColumn $column): string { - return 'TIMESTAMP'; + return ' TIMESTAMP DEFAULT CURRENT_TIMESTAMP() '; } /** @@ -319,6 +319,15 @@ protected function handleModifierComment(BaseColumn $column): string return $column->get('comment') ? ' COMMENT \'' . $column->get('comment') . '\'' : ''; } + /** + * @param BaseColumn $column + * @return string + */ + protected function handleModifierOnUpdateCurrentTimeStamp(BaseColumn $column): string + { + return $column->get('onUpdateCurrentTimeStamp') ? ' ON UPDATE CURRENT_TIMESTAMP() ' : ''; + } + /** * @param BaseColumn $column * @return string From ca479f1983c03f489345bb88fc761dd217a4c1ca Mon Sep 17 00:00:00 2001 From: smiPC Date: Mon, 22 Sep 2025 11:52:47 +0300 Subject: [PATCH 3/5] collate method added --- src/Schema/BaseColumn.php | 9 +++++++++ src/Schema/Compiler.php | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Schema/BaseColumn.php b/src/Schema/BaseColumn.php index 9c8b2c5..da32440 100644 --- a/src/Schema/BaseColumn.php +++ b/src/Schema/BaseColumn.php @@ -135,6 +135,15 @@ public function description(string $comment): self return $this->set('comment', $comment); } + /** + * @param string $value + * @return $this + */ + public function collate(string $value): self + { + return $this->set('collate', $value); + } + /** * @return $this */ diff --git a/src/Schema/Compiler.php b/src/Schema/Compiler.php index 409fcdf..81ac5dc 100644 --- a/src/Schema/Compiler.php +++ b/src/Schema/Compiler.php @@ -31,7 +31,7 @@ class Compiler protected $params = []; /** @var string[] */ - protected $modifiers = ['unsigned', 'nullable', 'default', 'autoincrement', 'comment', 'onUpdateCurrentTimeStamp']; + protected $modifiers = ['unsigned', 'nullable', 'default', 'autoincrement', 'comment', 'onUpdateCurrentTimeStamp', 'collate']; /** @var string[] */ protected $serials = ['tiny', 'small', 'normal', 'medium', 'big']; @@ -328,6 +328,15 @@ protected function handleModifierOnUpdateCurrentTimeStamp(BaseColumn $column): s return $column->get('onUpdateCurrentTimeStamp') ? ' ON UPDATE CURRENT_TIMESTAMP() ' : ''; } + /** + * @param BaseColumn $column + * @return string + */ + protected function handleModifierCollate(BaseColumn $column): string + { + return $column->get('collate') ? ' COLLATE ' . $column->get('collate') : ''; + } + /** * @param BaseColumn $column * @return string @@ -570,6 +579,7 @@ protected function handleAddForeign(AlterTable $table, $data): string * @param $data * @return string */ + protected function handleSetDefaultValue(AlterTable $table, $data): string { return 'ALTER TABLE ' . $this->wrap($table->getTableName()) . ' ALTER COLUMN ' From 3a23e567483de7785fe08828e7e751c170cab213 Mon Sep 17 00:00:00 2001 From: smiPC Date: Mon, 22 Sep 2025 12:05:47 +0300 Subject: [PATCH 4/5] nullable method added --- src/Schema/BaseColumn.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Schema/BaseColumn.php b/src/Schema/BaseColumn.php index da32440..a490bf8 100644 --- a/src/Schema/BaseColumn.php +++ b/src/Schema/BaseColumn.php @@ -126,6 +126,14 @@ public function notNull(): self return $this->set('nullable', false); } + /** + * @return $this + */ + public function nullable(): self + { + return $this->set('nullable', true); + } + /** * @param string $comment * @return $this From 8deb827c96f0e8fd4a3590cb413bf11edfb2ec3f Mon Sep 17 00:00:00 2001 From: smiPC Date: Mon, 22 Sep 2025 12:12:08 +0300 Subject: [PATCH 5/5] modified the operation of the timestamps method --- src/Schema/CreateTable.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Schema/CreateTable.php b/src/Schema/CreateTable.php index b160c4b..95aca85 100644 --- a/src/Schema/CreateTable.php +++ b/src/Schema/CreateTable.php @@ -366,14 +366,17 @@ public function softDelete(string $column = 'deleted_at'): self } /** - * @param string $createColumn - * @param string $updateColumn * @return $this */ - public function timestamps(string $createColumn = 'created_at', string $updateColumn = 'updated_at'): self + public function timestamps($fields = []): self { - $this->dateTime($createColumn)->notNull(); - $this->dateTime($updateColumn); + if (!is_array($fields)) + $fields = [$fields]; + foreach ($fields as $field) + $this->timestamp($field); + + $this->timestamp('created_at'); + $this->timestamp('updated_at'); return $this; } }