Skip to content

Commit 32d3f2a

Browse files
committed
Fix #236 Add useCurrentOnUpdate support to datetime column type
1 parent 2633f22 commit 32d3f2a

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/Database/Models/MySQL/MySQLColumn.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public function __construct(string $table, array $column)
7676

7777
case ColumnType::SOFT_DELETES:
7878
case ColumnType::SOFT_DELETES_TZ:
79+
case ColumnType::DATETIME:
80+
case ColumnType::DATETIME_TZ:
7981
case ColumnType::TIMESTAMP:
8082
case ColumnType::TIMESTAMP_TZ:
8183
$this->onUpdateCurrentTimestamp = $this->hasOnUpdateCurrentTimestamp();

src/Repositories/MySQLRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function isOnUpdateCurrentTimestamp(string $table, string $column): bool
3636
$result = DB::selectOne(
3737
"SHOW COLUMNS FROM `$table`
3838
WHERE Field = '$column'
39-
AND Type = 'timestamp'
39+
AND Type IN ('timestamp', 'datetime')
4040
AND Extra LIKE '%on update CURRENT_TIMESTAMP%'",
4141
);
4242
return !($result === null);

src/Schema/Models/Column.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function getSpatialSrID(): ?int;
9595

9696
/**
9797
* Check if the column uses "on update CURRENT_TIMESTAMP".
98-
* This is usually used for MySQL `timestamp` and `timestampTz`.
98+
* This is usually used for MySQL `timestamp` and `datetime`.
9999
*/
100100
public function isOnUpdateCurrentTimestamp(): bool;
101101

tests/resources/database/migrations/general/2020_03_21_000000_expected_create_timestamps_table.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ public function up()
8282
$table->timestampTz('created_at')->nullable();
8383
$table->timestampTz('update_at')->nullable()->useCurrent()->useCurrentOnUpdate();
8484
});
85+
86+
Schema::create('use_current_on_update', function (Blueprint $table) {
87+
$table->increments('id');
88+
$table->dateTime('datetime_useCurrentOnUpdate_nullable_useCurrent')->useCurrentOnUpdate()->nullable()->useCurrent();
89+
$table->dateTime('datetime_useCurrentOnUpdate_useCurrent')->useCurrentOnUpdate()->useCurrent();
90+
$table->dateTime('datetime_nullable')->useCurrentOnUpdate()->nullable();
91+
$table->dateTime('datetime_useCurrent')->useCurrent();
92+
$table->dateTime('datetime_useCurrentOnUpdate')->useCurrentOnUpdate();
93+
$table->timestamp('timestamp_useCurrentOnUpdate_nullable_useCurrent')->useCurrentOnUpdate()->nullable()->useCurrent();
94+
$table->timestamp('timestamp_useCurrentOnUpdate_useCurrent')->useCurrentOnUpdate()->useCurrent();
95+
$table->timestamp('timestamp_nullable')->useCurrentOnUpdate()->nullable();
96+
$table->timestamp('timestamp_useCurrent')->useCurrent();
97+
$table->timestamp('timestamp_useCurrentOnUpdate')->useCurrentOnUpdate()->default('2024-10-08 00:00:00');
98+
99+
});
85100
}
86101

87102
/**

0 commit comments

Comments
 (0)