Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Db/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,10 @@ public function getColumnTypes(): array
'decimal',
'double',
'datetime',
'datetimefractional',
'timestamp',
'timestampfractional',
'timestamptimezone',
'time',
'date',
'blob',
Expand Down
29 changes: 29 additions & 0 deletions tests/TestCase/Command/BakeMigrationSnapshotCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,35 @@ public function testSnapshotGenerateOnly()
$this->assertFalse(file_exists($this->migrationPath . 'schema-dump-test.lock'), 'Lock file should not be created with --generate-only');
}

public function testSnapshotPostgresTimestampTzColumn(): void
{
$this->skipIf(env('DB') !== 'pgsql');

/** @var \Cake\Database\Connection $connection */
$connection = ConnectionManager::get('test');
$connection->execute(
'CREATE TABLE IF NOT EXISTS postgres_timestamp_tz (id SERIAL PRIMARY KEY, created TIMESTAMPTZ NOT NULL)',
);

$scenario = 'PostgresTimestampTz';

$bakeName = $this->getBakeName("TestSnapshot{$scenario}");
$this->exec("bake migration_snapshot {$bakeName} -c test");

$connection->execute('DROP TABLE postgres_timestamp_tz');

$generatedMigration = glob($this->migrationPath . "*_TestSnapshot{$scenario}*.php");
$this->generatedFiles = $generatedMigration;
$this->generatedFiles[] = $this->migrationPath . 'schema-dump-test.lock';

$generatedMigration = basename($generatedMigration[0]);
$fileName = pathinfo($generatedMigration, PATHINFO_FILENAME);
$this->assertOutputContains('Marking the migration ' . $fileName . ' as migrated...');
$this->assertOutputContains('Creating a dump of the new database state...');
$this->assertNotEmpty($this->generatedFiles);
$this->assertCorrectSnapshot($bakeName, file_get_contents($this->generatedFiles[0]));
}

/**
* Test baking a snapshot with the phinx auto-id feature disabled
*
Expand Down
17 changes: 17 additions & 0 deletions tests/TestCase/Migration/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2829,6 +2829,23 @@ public function testPostgresFullMigration(): void
$this->assertFalse($adapter->hasTable('users'));
}

public function testPostgresTimestamptimezone(): void
{
if ($this->getDriverType() !== 'postgres') {
$this->markTestSkipped('Test requires postgres');
}
$adapter = $this->prepareEnvironment([
'migrations' => ROOT . '/config/PostgresTimestamptimezone',
]);
$adapter->connect();
// migrate to the latest version
$this->manager->migrate();

$this->assertTrue($adapter->hasTable('timestamp_articles'));

$this->manager->rollback('all');
}

public function testMigrationWithDropColumnAndForeignKeyAndIndex(): void
{
if ($this->getDriverType() !== 'mysql') {
Expand Down
Loading