Skip to content

Commit e6c435d

Browse files
committed
feature #912 [Store] Add a way to configure the setup options for mariadb store (lyrixx)
This PR was merged into the main branch. Discussion ---------- [Store] Add a way to configure the setup options for mariadb store | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | | Issues | Fix #901 | License | MIT Commits ------- 1398d76 [Store] Add a way to configure the setup options for mariadb store
2 parents f78ac35 + 1398d76 commit e6c435d

File tree

6 files changed

+31
-9
lines changed

6 files changed

+31
-9
lines changed

src/ai-bundle/config/options.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,11 @@
598598
->stringNode('table_name')->cannotBeEmpty()->end()
599599
->stringNode('index_name')->cannotBeEmpty()->end()
600600
->stringNode('vector_field_name')->cannotBeEmpty()->end()
601+
->arrayNode('setup_options')
602+
->children()
603+
->integerNode('dimensions')->end()
604+
->end()
605+
->end()
601606
->end()
602607
->end()
603608
->end()

src/ai-bundle/config/services.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
->set('ai.command.setup_store', SetupStoreCommand::class)
206206
->args([
207207
tagged_locator('ai.store', 'name'),
208+
abstract_arg('setup store options'),
208209
])
209210
->tag('console.command')
210211
->set('ai.command.drop_store', DropStoreCommand::class)

src/ai-bundle/src/AiBundle.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,11 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
169169
$this->processMultiAgentConfig($multiAgentName, $multiAgent, $builder);
170170
}
171171

172+
$setupStoresOptions = [];
172173
foreach ($config['store'] ?? [] as $type => $store) {
173-
$this->processStoreConfig($type, $store, $builder);
174+
$this->processStoreConfig($type, $store, $builder, $setupStoresOptions);
174175
}
176+
$builder->getDefinition('ai.command.setup_store')->setArgument(1, $setupStoresOptions);
175177

176178
$stores = array_keys($builder->findTaggedServiceIds('ai.store'));
177179

@@ -898,8 +900,9 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
898900

899901
/**
900902
* @param array<string, mixed> $stores
903+
* @param array<string, mixed> $setupStoresOptions
901904
*/
902-
private function processStoreConfig(string $type, array $stores, ContainerBuilder $container): void
905+
private function processStoreConfig(string $type, array $stores, ContainerBuilder $container, &$setupStoresOptions): void
903906
{
904907
if ('azure_search' === $type) {
905908
foreach ($stores as $name => $store) {
@@ -1093,6 +1096,8 @@ private function processStoreConfig(string $type, array $stores, ContainerBuilde
10931096
$container->setDefinition($serviceId, $definition);
10941097
$container->registerAliasForArgument($serviceId, StoreInterface::class, $name);
10951098
$container->registerAliasForArgument($serviceId, StoreInterface::class, $type.'_'.$name);
1099+
1100+
$setupStoresOptions[$serviceId] = $store['setup_options'] ?? [];
10961101
}
10971102
}
10981103

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ public function testStoreCommandsAreDefined()
123123
$this->assertTrue($container->hasDefinition('ai.command.setup_store'));
124124

125125
$setupStoreCommandDefinition = $container->getDefinition('ai.command.setup_store');
126-
$this->assertCount(1, $setupStoreCommandDefinition->getArguments());
126+
$this->assertCount(2, $setupStoreCommandDefinition->getArguments());
127+
$this->assertSame(['ai.store.mariadb.my_mariadb_store' => ['dimensions' => 1024]], $setupStoreCommandDefinition->getArgument(1));
127128
$this->assertArrayHasKey('console.command', $setupStoreCommandDefinition->getTags());
128129

129130
$this->assertTrue($container->hasDefinition('ai.command.drop_store'));
@@ -3502,6 +3503,9 @@ private function getFullConfig(): array
35023503
'table_name' => 'vector_table',
35033504
'index_name' => 'vector_idx',
35043505
'vector_field_name' => 'vector',
3506+
'setup_options' => [
3507+
'dimensions' => 1024,
3508+
],
35053509
],
35063510
],
35073511
'meilisearch' => [

src/store/src/Command/SetupStoreCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ final class SetupStoreCommand extends Command
3131
{
3232
/**
3333
* @param ServiceLocator<ManagedStoreInterface> $stores
34+
* @param array<string, mixed> $setupStoresOptions
3435
*/
3536
public function __construct(
3637
private readonly ServiceLocator $stores,
38+
private readonly array $setupStoresOptions = [],
3739
) {
3840
parent::__construct();
3941
}
@@ -84,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8486
$store = $this->stores->get($storeName);
8587

8688
try {
87-
$store->setup();
89+
$store->setup($this->setupStoresOptions[$storeName] ?? []);
8890
$io->success(\sprintf('The "%s" store was set up successfully.', $storeName));
8991
} catch (\Exception $e) {
9092
throw new RuntimeException(\sprintf('An error occurred while setting up the "%s" store: ', $storeName).$e->getMessage(), previous: $e);

src/store/tests/Command/SetupStoreCommandTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ public function testCommandCannotSetupStoreWithException()
9090
public function testCommandCanSetupDefinedStore()
9191
{
9292
$store = $this->createMock(ManagedStoreInterface::class);
93-
$store->expects($this->once())->method('setup');
94-
95-
$command = new SetupStoreCommand(new ServiceLocator([
96-
'foo' => static fn (): object => $store,
97-
]));
93+
$store->expects($this->once())->method('setup')->with(['some_option' => 'some_value']);
94+
95+
$command = new SetupStoreCommand(
96+
new ServiceLocator([
97+
'foo' => static fn (): object => $store,
98+
]),
99+
[
100+
'foo' => ['some_option' => 'some_value'],
101+
]
102+
);
98103

99104
$tester = new CommandTester($command);
100105

0 commit comments

Comments
 (0)