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
16 changes: 16 additions & 0 deletions documentation/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ to_pgsql_table($client, 'users')->withTypesMap(new EntryTypesMap(
));
```

### 6) `flow-php/symfony-postgresql-messenger` - `messenger_messages` time columns use `timestamp` instead of `timestamptz`

| Column type for `created_at`, `available_at`, `delivered_at` | Before | After |
|--------------------------------------------------------------|---------------|-------------|
| `MessengerCatalogProvider` (DDL) | `timestamptz` | `timestamp` |
| `Connection` bindings | `TIMESTAMPTZ` | `TIMESTAMP` |

Existing tables, realign the column type (UTC instants preserved):

```sql
ALTER TABLE messenger_messages
ALTER COLUMN created_at TYPE timestamp USING created_at AT TIME ZONE 'UTC',
ALTER COLUMN available_at TYPE timestamp USING available_at AT TIME ZONE 'UTC',
ALTER COLUMN delivered_at TYPE timestamp USING delivered_at AT TIME ZONE 'UTC';
```

---

## Upgrading from 0.37.x to 0.38.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public function get(): ?array
->forUpdateSkipLocked(),
[
$this->queueName,
typed($now, ValueType::TIMESTAMPTZ),
typed($redeliverCutoff, ValueType::TIMESTAMPTZ),
typed($now, ValueType::TIMESTAMP),
typed($redeliverCutoff, ValueType::TIMESTAMP),
],
);

Expand All @@ -129,7 +129,7 @@ public function get(): ?array
->set('delivered_at', param(1))
->where(eq(col('id'), param(2))),
[
typed($now, ValueType::TIMESTAMPTZ),
typed($now, ValueType::TIMESTAMP),
(int) $rowId,
],
);
Expand All @@ -152,7 +152,7 @@ public function getMessageCount(): int
)),
[
$this->queueName,
typed($now, ValueType::TIMESTAMPTZ),
typed($now, ValueType::TIMESTAMP),
],
);
}
Expand All @@ -173,7 +173,7 @@ public function keepalive(string $id, ?int $seconds = null): void
->set('delivered_at', param(1))
->where(eq(col('id'), param(2))),
[
typed(new DateTimeImmutable('now'), ValueType::TIMESTAMPTZ),
typed(new DateTimeImmutable('now'), ValueType::TIMESTAMP),
(int) $id,
],
);
Expand Down Expand Up @@ -202,8 +202,8 @@ public function send(string $body, array $headers, int $delay = 0): string
$body,
json_encode($headers, JSON_THROW_ON_ERROR),
$this->queueName,
typed($now, ValueType::TIMESTAMPTZ),
typed($availableAt, ValueType::TIMESTAMPTZ),
typed($now, ValueType::TIMESTAMP),
typed($availableAt, ValueType::TIMESTAMP),
],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use function Flow\PostgreSql\DSL\schema;
use function Flow\PostgreSql\DSL\schema_column;
use function Flow\PostgreSql\DSL\schema_column_text;
use function Flow\PostgreSql\DSL\schema_column_timestamp_tz;
use function Flow\PostgreSql\DSL\schema_column_timestamp;
use function Flow\PostgreSql\DSL\schema_column_varchar;
use function Flow\PostgreSql\DSL\schema_index;
use function Flow\PostgreSql\DSL\schema_primary_key;
Expand Down Expand Up @@ -42,9 +42,9 @@ public function get(): Catalog
schema_column_text('body', nullable: false),
schema_column_text('headers', nullable: false),
schema_column_varchar('queue_name', 190, nullable: false, default: 'default'),
schema_column_timestamp_tz('created_at', nullable: false),
schema_column_timestamp_tz('available_at', nullable: false),
schema_column_timestamp_tz('delivered_at', nullable: true),
schema_column_timestamp('created_at', nullable: false),
schema_column_timestamp('available_at', nullable: false),
schema_column_timestamp('delivered_at', nullable: true),
],
primaryKey: schema_primary_key(['id']),
indexes: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Flow\Bridge\Symfony\PostgreSQLMessenger\Tests\Unit;

use Flow\Bridge\Symfony\PostgreSQLMessenger\MessengerCatalogProvider;
use Flow\PostgreSql\QueryBuilder\Schema\ColumnType;
use Flow\PostgreSql\Schema\IdentityGeneration;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -93,6 +94,17 @@ public function test_table_has_default_name(): void
static::assertSame('messenger_messages', $table->name);
}

public function test_timestamp_columns_use_timestamp_without_time_zone(): void
{
$provider = new MessengerCatalogProvider();
$table = $provider->get()->get('public')->tables[0];

static::assertTrue($table->column('created_at')->type->isEqual(ColumnType::timestamp()));
static::assertTrue($table->column('available_at')->type->isEqual(ColumnType::timestamp()));
static::assertTrue($table->column('delivered_at')->type->isEqual(ColumnType::timestamp()));
static::assertFalse($table->column('created_at')->type->isEqual(ColumnType::timestamptz()));
}

public function test_table_has_expected_columns(): void
{
$provider = new MessengerCatalogProvider();
Expand Down
Loading