diff --git a/config/timestream.php b/config/timestream.php index 072ccc9..b140055 100644 --- a/config/timestream.php +++ b/config/timestream.php @@ -24,7 +24,7 @@ 'database' => env('AWS_TIMESTREAM_DATABASE'), /** - * Enable query and metedata logging on server + * Enable query and metadata logging on server */ 'debug_query' => env('TIMESTREAM_DEBUG_QUERY', false), @@ -33,16 +33,11 @@ */ 'tables' => [ /** - * Default table table name + * To handle multiple tables access, you can map them below using key value pair. + * The `value` should represent the table name that you want to access + * The `key` is an alias to the table name that can be anything meaningful. + * eg. ['listing' => 'listing-kpi', 'github' => 'ingestion-github', 'prod' => 'prod'] */ - 'default' => null, - - /** - * To handle multiple tables acess, you can map them below and access them. - * The `value` of the `key` should represent the table name that you want to access - * and they `key` can be anything meaningful. - * eg. ['listing' => 'listing-kpi', ['github' => 'ingestion-github']] - */ - 'sources' => [], + 'aliases' => [], ], ]; diff --git a/src/Dto/AbstractTimestreamDto.php b/src/Dto/AbstractTimestreamDto.php index 2dbe58c..7f2805e 100644 --- a/src/Dto/AbstractTimestreamDto.php +++ b/src/Dto/AbstractTimestreamDto.php @@ -17,9 +17,9 @@ public function onDataBase(string $databaseName): self return $this; } - public function forTable(string $source): self + public function forTable(string $alias): self { - $this->table = $this->tables[$source]; + $this->table = $this->tables[$alias]; return $this; } diff --git a/src/Dto/TimestreamReaderDto.php b/src/Dto/TimestreamReaderDto.php index ef6b819..6baa629 100644 --- a/src/Dto/TimestreamReaderDto.php +++ b/src/Dto/TimestreamReaderDto.php @@ -9,7 +9,7 @@ final class TimestreamReaderDto extends AbstractTimestreamDto public function __construct(protected Builder $builder, string $forTable = null) { $this->database = config('timestream.database'); - $this->tables = config('timestream.tables.sources'); + $this->tables = config('timestream.tables.aliases'); if ($forTable) { $this->forTable($forTable); diff --git a/src/Dto/TimestreamWriterDto.php b/src/Dto/TimestreamWriterDto.php index 515433a..8ba166d 100644 --- a/src/Dto/TimestreamWriterDto.php +++ b/src/Dto/TimestreamWriterDto.php @@ -7,7 +7,7 @@ final class TimestreamWriterDto extends AbstractTimestreamDto public function __construct(protected array $records, protected array $commonAttributes = [], string $forTable = null) { $this->database = config('timestream.database'); - $this->tables = config('timestream.tables.sources'); + $this->tables = config('timestream.tables.aliases'); if ($forTable) { $this->forTable($forTable); diff --git a/tests/Fixtures/Traits/ConfigurableTrait.php b/tests/Fixtures/Traits/ConfigurableTrait.php index 6eb7cee..e4429ee 100644 --- a/tests/Fixtures/Traits/ConfigurableTrait.php +++ b/tests/Fixtures/Traits/ConfigurableTrait.php @@ -11,8 +11,7 @@ public function getTimestreamConfig(): array 'secret' => env('AWS_TIMESTREAM_SECRET'), 'database' => 'test-db', 'tables' => [ - 'default' => 'default', - 'sources' => [ + 'aliases' => [ 'test' => 'default', ], ], diff --git a/tests/Unit/ReaderUnitTest.php b/tests/Unit/ReaderUnitTest.php index d47f70d..45684bb 100644 --- a/tests/Unit/ReaderUnitTest.php +++ b/tests/Unit/ReaderUnitTest.php @@ -55,11 +55,11 @@ public function test_reader_dto_can_inject_database_and_table_for_sql_query() ->whereIn('measure_value::varchar', ['reviewer', 'open', 'closed']) ->orderBy('time', 'desc'); - $tableSource = 'test'; - $dto = TimestreamReaderDto::make($queryBuilder, $tableSource); + $alias = 'test'; + $dto = TimestreamReaderDto::make($queryBuilder, $alias); $database = config('timestream.database'); - $table = config("timestream.tables.sources.{$tableSource}"); + $table = config("timestream.tables.aliases.{$alias}"); $this->assertStringContainsString("FROM \"{$database}\".\"{$table}\"", $dto->toArray()['QueryString']); } } diff --git a/tests/Unit/WriterUnitTest.php b/tests/Unit/WriterUnitTest.php index b4aca6d..8b5440b 100644 --- a/tests/Unit/WriterUnitTest.php +++ b/tests/Unit/WriterUnitTest.php @@ -207,18 +207,18 @@ public function test_it_should_ingest_to_correct_database_name_and_table_name() $metrics['dimensions'] )->toArray(); - $table = 'test'; - $timestreamWriter = TimestreamWriterDto::make($payload)->forTable($table); + $alias = 'test'; + $timestreamWriter = TimestreamWriterDto::make($payload)->forTable($alias); $payload = $timestreamWriter->toArray(); $this->assertEquals(config('timestream.database'), $payload['DatabaseName']); - $this->assertEquals(config("timestream.tables.sources.{$table}"), $payload['TableName']); + $this->assertEquals(config("timestream.tables.aliases.{$alias}"), $payload['TableName']); - $timestreamWriter = TimestreamWriterDto::make($payload, [], $table); + $timestreamWriter = TimestreamWriterDto::make($payload, [], $alias); $payload = $timestreamWriter->toArray(); $this->assertEquals(config('timestream.database'), $payload['DatabaseName']); - $this->assertEquals(config("timestream.tables.sources.{$table}"), $payload['TableName']); + $this->assertEquals(config("timestream.tables.aliases.{$alias}"), $payload['TableName']); } private function generateMetrics(): array