You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -587,6 +588,68 @@ Schema::table('book', function (Blueprint $table) {
587
588
});
588
589
```
589
590
591
+
#### Temporal Indexes
592
+
593
+
Imagine you've built a shopping system and one day a customer complains that his order was sent to their old address, which is hundreds of miles away from the current one.
594
+
The current data in the database also shows you the current address - so you made a mistake?
595
+
But how was the address when the order was shipped?
596
+
Have you logged the change in an audit table?
597
+
Happy for you if you did, but querying the data is complicated...
598
+
599
+
So PostgreSQL 18 added support for temporal database features:
600
+
You can now version control your data with primary keys, unique keys and foreign keys that are only valid for a specific point in time:
601
+
602
+
```php
603
+
use Tpetry\PostgresqlEnhanced\Schema\Blueprint;
604
+
use Tpetry\PostgresqlEnhanced\Support\Facades\Schema;
605
+
606
+
Schema::createExtensionIfNotExists('btree_gist');
607
+
Schema::create('addresses', function (Blueprint $table) {
608
+
$table->uuid('id');
609
+
$table->timestampTzRange('valid');
610
+
// ...
611
+
612
+
$table->primary(['id', 'valid WITHOUT OVERLAPS']);
613
+
});
614
+
Schema::create('orders', function (Blueprint $table) {
615
+
$table->uuid('id');
616
+
$table->uuid('address_id');
617
+
$table->text('reference_nr');
618
+
$table->timestampTzRange('valid');
619
+
// ...
620
+
621
+
$table->primary(['id', 'valid WITHOUT OVERLAPS']);
622
+
$table->unique(['reference_nr', 'valid WITHOUT OVERLAPS']);
0 commit comments