Skip to content

Commit 118718b

Browse files
authored
fix modified column being nullable (#1026)
* fix modified column being nullable * update all schema dump lock files + add a script to automatically update those schema dump files
1 parent d6720e1 commit 118718b

16 files changed

+247
-12
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"require-dev": {
3131
"cakephp/bake": "^3.3",
32-
"cakephp/cakephp": "^5.3.0",
32+
"cakephp/cakephp": "^5.3.2",
3333
"cakephp/cakephp-codesniffer": "^5.0",
3434
"phpunit/phpunit": "^11.5.3 || ^12.1.3"
3535
},

src/Db/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,8 @@ public function addTimestamps(string|false|null $createdAt = 'created', string|f
729729
}
730730
if ($updatedAt) {
731731
$this->addColumn($updatedAt, $timestampType, [
732-
'null' => true,
733-
'default' => null,
732+
'null' => false,
733+
'default' => 'CURRENT_TIMESTAMP',
734734
'update' => 'CURRENT_TIMESTAMP',
735735
'timezone' => $withTimezone,
736736
]);

tests/TestCase/Db/Adapter/MysqlAdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,8 @@ public function testAddTimestampsFeatureFlag()
576576
$this->assertEquals('updated', $columns[2]->getName());
577577
$this->assertEquals('datetime', $columns[2]->getType());
578578
$this->assertContains($columns[2]->getUpdate(), ['CURRENT_TIMESTAMP', 'current_timestamp()']);
579-
$this->assertTrue($columns[2]->isNull());
580-
$this->assertNull($columns[2]->getDefault());
579+
$this->assertFalse($columns[2]->isNull());
580+
$this->assertContains($columns[2]->getDefault(), ['CURRENT_TIMESTAMP', 'current_timestamp()']);
581581
}
582582

583583
public function testCreateTableWithSchema()

tests/TestCase/Db/Adapter/SqliteAdapterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2092,7 +2092,7 @@ public function testAlterTableColumnAdd()
20922092
['name' => 'string_col_2', 'type' => 'string', 'default' => null, 'null' => true],
20932093
['name' => 'string_col_3', 'type' => 'string', 'default' => null, 'null' => false],
20942094
['name' => 'created', 'type' => 'timestamp', 'default' => 'CURRENT_TIMESTAMP', 'null' => false],
2095-
['name' => 'updated', 'type' => 'timestamp', 'default' => null, 'null' => true],
2095+
['name' => 'updated', 'type' => 'timestamp', 'default' => 'CURRENT_TIMESTAMP', 'null' => false],
20962096
];
20972097

20982098
$this->assertEquals(count($expected), count($columns));

tests/TestCase/Db/Table/TableTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ public function testAddTimestamps(
195195
$this->assertEquals('timestamp', $columns[1]->getType());
196196
$this->assertEquals($withTimezone, $columns[1]->getTimezone());
197197
$this->assertEquals('CURRENT_TIMESTAMP', $columns[1]->getUpdate());
198-
$this->assertTrue($columns[1]->isNull());
199-
$this->assertNull($columns[1]->getDefault());
198+
$this->assertFalse($columns[1]->isNull());
199+
$this->assertEquals('CURRENT_TIMESTAMP', $columns[1]->getDefault());
200200
}
201201

202202
/**
@@ -246,8 +246,8 @@ public function testAddTimestampsNoCreated(AdapterInterface $adapter)
246246
$this->assertSame('timestamp', $columns[0]->getType());
247247
$this->assertFalse($columns[0]->getTimezone());
248248
$this->assertSame('CURRENT_TIMESTAMP', $columns[0]->getUpdate());
249-
$this->assertTrue($columns[0]->isNull());
250-
$this->assertNull($columns[0]->getDefault());
249+
$this->assertFalse($columns[0]->isNull());
250+
$this->assertSame('CURRENT_TIMESTAMP', $columns[0]->getDefault());
251251
}
252252

253253
/**
@@ -299,8 +299,8 @@ public function testAddTimestampsWithTimezone(
299299
$this->assertEquals('timestamp', $columns[1]->getType());
300300
$this->assertTrue($columns[1]->getTimezone());
301301
$this->assertEquals('CURRENT_TIMESTAMP', $columns[1]->getUpdate());
302-
$this->assertTrue($columns[1]->isNull());
303-
$this->assertNull($columns[1]->getDefault());
302+
$this->assertFalse($columns[1]->isNull());
303+
$this->assertEquals('CURRENT_TIMESTAMP', $columns[1]->getDefault());
304304
}
305305

306306
public function testInsert()
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)