@@ -83,7 +83,8 @@ The minimal breaking changes of the past years are listed in the [breaking chang
8383 - [ Refresh Data on Save] ( #refresh-data-on-save )
8484 - [ Date Formats] ( #date-formats )
8585- [ Expressions] ( #expressions )
86-
86+ - [ Supported Extensions] ( #supported-extensions )
87+ - [ Timescale] ( #timescale )
8788## IDE Autocomplete
8889
8990Laravel provides many extension capabilities, making it hard for IDEs to do proper autocomplete.
@@ -1338,6 +1339,93 @@ Schema::create('comments', function (Blueprint $table) {
13381339});
13391340```
13401341
1342+ # Supported Extensions
1343+
1344+ You can use any extension with this PostgreSQL you like but some have received a deeper Laravel integration.
1345+
1346+ ## Timescale
1347+
1348+ Timescale is fantastic and has many features.
1349+ Therefore, it is impossible to explain everything here; consult their docs about the different features this extension provides.
1350+ Here's a list of supported features and an example showcasing its usage:
1351+
1352+ | Feature | Actions |
1353+ | -----------------------| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1354+ | Hypertable | ` new CreateHypertable(string $column, string\|int $interval, string $partitionFunction = null) ` <br />` new ChangeChunkTimeInterval(string\|int $interval) ` |
1355+ | Chunk Skipping | ` new EnableChunkSkipping(string $column) ` <br />` new DisableChunkSkipping(string $column) ` |
1356+ | Compression | ` new EnableCompression(string\|array $orderBy = null, string\|array $segmentBy = null) ` <br /> ` new DisableCompression() ` <br />` new CreateCompressionPolicy(string\|int $compressAfter) ` <br />` new DropCompressionPolicy() ` <br />` new CompressChunks(DateTimeInterface\|string\|int $olderThan = null, DateTimeInterface\|string\|int $newerThan = null) ` <br />` new DecompressChunks(DateTimeInterface\|string\|int $olderThan = null, DateTimeInterface\|string\|int $newerThan = null) ` |
1357+ | Reordering | ` new CreateReorderPolicy(string $index) ` <br />` new CreateReorderPolicyByIndex(...$columns) ` <br />` new CreateReorderPolicyByUnique(...$columns) ` <br />` new DropReorderPolicy() ` <br />` new ReorderChunks(DateTimeInterface\|string\|int $olderThan = null, DateTimeInterface\|string\|int $newerThan = null) ` |
1358+ | Data Retention | ` new CreateRetentionPolicy(string\|int $dropAfter) ` <br />` new DropRetentionPolicy() ` <br />` new DropChunks(DateTimeInterface\|string\|int $olderThan = null, DateTimeInterface\|string\|int $newerThan = null) ` |
1359+ | Tiered Storage | ` new CreateTieringPolicy(string\|int $dropAfter) ` <br />` new DropTieringPolicy() ` <br />` new TierChunks(DateTimeInterface\|string\|int $olderThan = null, DateTimeInterface\|string\|int $newerThan = null) ` <br />` new UntierChunks(DateTimeInterface\|string\|int $olderThan = null, DateTimeInterface\|string\|int $newerThan = null) ` |
1360+ | Continuous Aggregates | ` new CreateRefreshPolicy(string $interval, string\|int\|null $start, string\|int\|null $end) ` <br />` new DropRefreshPolicy() ` <br />` new RefreshData(DateTimeInterface\|int\|null $start, DateTimeInterface\|int\|null $end) ` |
1361+
1362+ ``` php
1363+ use Illuminate\Database\Migrations\Migration;
1364+ use Illuminate\Database\Migrations\Migration;
1365+ use Tpetry\PostgresqlEnhanced\Schema\Timescale\Actions\CreateCompressionPolicy;
1366+ use Tpetry\PostgresqlEnhanced\Schema\Timescale\Actions\CreateHypertable;
1367+ use Tpetry\PostgresqlEnhanced\Schema\Timescale\Actions\CreateRefreshPolicy;
1368+ use Tpetry\PostgresqlEnhanced\Schema\Timescale\Actions\CreateReorderPolicyByIndex;
1369+ use Tpetry\PostgresqlEnhanced\Schema\Timescale\Actions\CreateRetentionPolicy;
1370+ use Tpetry\PostgresqlEnhanced\Schema\Timescale\Actions\EnableChunkSkipping;
1371+ use Tpetry\PostgresqlEnhanced\Schema\Timescale\Actions\EnableCompression;
1372+ use Tpetry\PostgresqlEnhanced\Schema\Timescale\CaggBlueprint;
1373+ use Tpetry\PostgresqlEnhanced\Support\Facades\Schema;
1374+ use Tpetry\PostgresqlEnhanced\Schema\Blueprint;
1375+
1376+ return new class extends Migration
1377+ {
1378+ public function up(): void
1379+ {
1380+ Schema::createExtensionIfNotExists('timescaledb');
1381+
1382+ Schema::create('visits', function (Blueprint $table) {
1383+ $table->identity();
1384+ $table->bigInteger('website_id');
1385+ $table->text('url');
1386+ $table->float('duration');
1387+ $table->timestampTz('created_at')->nullable();
1388+
1389+ $table->primary(['id', 'created_at']);
1390+ $table->index(['website_id', 'created_at']);
1391+
1392+ $table->timescale(
1393+ new CreateHypertable('created_at', '1 day'),
1394+ new CreateReorderPolicyByIndex('website_id', 'created_at'),
1395+ new EnableCompression(segmentBy: 'website_id'),
1396+ new CreateCompressionPolicy('3 days'),
1397+ new CreateRetentionPolicy('1 year'),
1398+ new EnableChunkSkipping('id'),
1399+ );
1400+ });
1401+
1402+ Schema::continuousAggregate('visits_agg', function(CaggBlueprint $table) {
1403+ $table->as("
1404+ SELECT
1405+ time_bucket('1 hour', created_at) AS bucket,
1406+ website_id,
1407+ url,
1408+ SUM(duration) AS duration
1409+ FROM visits
1410+ GROUP BY bucket, website_id, url
1411+ ");
1412+ $table->realtime();
1413+ $table->index(['website_id','url']);
1414+
1415+ $table->timescale(
1416+ new CreateRefreshPolicy('5 minutes', '1 days', '2 hours'),
1417+ new EnableCompression(),
1418+ new CreateCompressionPolicy('2 days'),
1419+ );
1420+ });
1421+ }
1422+ };
1423+ ```
1424+
1425+ > [ !WARNING]
1426+ > Indexes are not automatically created when creating hypertables or continuous aggregates.
1427+ > You have to create them manually.
1428+
13411429# Breaking Changes
13421430
13431431* ** 2.0.0**
0 commit comments