Skip to content

Commit 53c0141

Browse files
authored
Merge pull request #4 from Spameri/migrate-command
Migrate command
2 parents e86af35 + 3071023 commit 53c0141

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+5932
-62
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@
2525
],
2626
"require": {
2727
"php": ">=7.1",
28+
"ext-json": "*",
2829
"nette/di": "^2.4.10",
2930
"nette/security": "^2.4.3",
3031
"nette/utils": "^2.5.3",
31-
"spameri/elastic-query": "^0.3.0",
32+
"spameri/elastic-query": "^0.5.0",
3233
"elasticsearch/elasticsearch": "^6.0",
3334
"kdyby/console": "^2.7.1",
3435
"kdyby/datetime-provider": "v1.0.0",
3536
"kdyby/monolog": "^1.3.2",
36-
"tracy/tracy": "^2.5.3"
37+
"tracy/tracy": "^2.6.0"
3738
},
3839
"require-dev": {
3940
"spameri/coding-standard": "dev-master",
41+
"spameri/dependency-mocker": "^1.3",
4042
"nette/tester": "^2.2.0",
4143
"phpstan/phpstan-shim": "^0.11.5",
4244
"php-coveralls/php-coveralls": "^2.1",

makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: tests
2+
.PHONY: tests-local
3+
.PHONY: phpstan
4+
.PHONY: cs
5+
6+
7+
tests:
8+
vendor/bin/tester -s -c ./tests/php.ini-unix ./tests
9+
10+
tests-local:
11+
vendor/bin/tester -c ./tests/SpameriTests/php.ini tests
12+
13+
phpstan:
14+
vendor/bin/phpstan analyse -l 7 -c phpstan.neon src tests
15+
16+
cs:
17+
vendor/bin/phpcs --standard=vendor/spameri/coding-standard/src/ruleset.xml src tests

src/Commands/DumpIndex.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\Elastic\Commands;
4+
5+
6+
class DumpIndex extends \Symfony\Component\Console\Command\Command
7+
{
8+
9+
/**
10+
* @var \Spameri\Elastic\Model\DumpIndex
11+
*/
12+
private $dumpIndex;
13+
14+
15+
public function __construct(
16+
\Spameri\Elastic\Model\DumpIndex $migrate
17+
)
18+
{
19+
parent::__construct(NULL);
20+
$this->dumpIndex = $migrate;
21+
}
22+
23+
24+
/**
25+
* @example spameri:elastic:dump-index index elasticDump.dump
26+
*/
27+
protected function configure() : void
28+
{
29+
$this
30+
->setName('spameri:elastic:dump-index')
31+
->setDescription('Dumps all data from index to file')
32+
->addArgument('index', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
33+
->addArgument('filename', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
34+
;
35+
}
36+
37+
38+
protected function execute(
39+
\Symfony\Component\Console\Input\InputInterface $input
40+
, \Symfony\Component\Console\Output\OutputInterface $output
41+
)
42+
{
43+
$output->writeln('Starting');
44+
45+
$index = $input->getArgument('index');
46+
$filename = $input->getArgument('filename');
47+
48+
$this->dumpIndex->setOutput($output);
49+
$this->dumpIndex->execute($index, $filename);
50+
51+
$output->writeln('Done');
52+
}
53+
54+
}

src/Commands/LoadDump.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\Elastic\Commands;
4+
5+
6+
class LoadDump extends \Symfony\Component\Console\Command\Command
7+
{
8+
9+
/**
10+
* @var \Spameri\Elastic\Model\RestoreIndex
11+
*/
12+
private $restoreIndex;
13+
14+
15+
public function __construct(
16+
\Spameri\Elastic\Model\RestoreIndex $migrate
17+
)
18+
{
19+
parent::__construct(NULL);
20+
$this->restoreIndex = $migrate;
21+
}
22+
23+
24+
/**
25+
* @example spameri:elastic:load-dump
26+
*/
27+
protected function configure() : void
28+
{
29+
$this
30+
->setName('spameri:elastic:load-dump')
31+
->setDescription('Loads data from provided dump file.')
32+
->addArgument('filename', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
33+
->addArgument(
34+
'step',
35+
\Symfony\Component\Console\Input\InputArgument::OPTIONAL,
36+
'Number of documents per one bulk index',
37+
500
38+
)
39+
;
40+
}
41+
42+
43+
protected function execute(
44+
\Symfony\Component\Console\Input\InputInterface $input
45+
, \Symfony\Component\Console\Output\OutputInterface $output
46+
)
47+
{
48+
$output->writeln('Starting');
49+
50+
$index = $input->getArgument('index');
51+
$step = (int) $input->getArgument('step');
52+
53+
$this->restoreIndex->setOutput($output);
54+
$this->restoreIndex->execute($index, $step);
55+
56+
$output->writeln('Done');
57+
}
58+
59+
}

src/Commands/TypeToNewIndex.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Spameri\Elastic\Commands;
4+
5+
6+
class TypeToNewIndex extends \Symfony\Component\Console\Command\Command
7+
{
8+
9+
/**
10+
* @var \Spameri\Elastic\Model\TypeToNewIndex\Migrate
11+
*/
12+
private $migrate;
13+
14+
15+
public function __construct(
16+
\Spameri\Elastic\Model\TypeToNewIndex\Migrate $migrate
17+
)
18+
{
19+
parent::__construct(NULL);
20+
$this->migrate = $migrate;
21+
}
22+
23+
24+
/**
25+
* @example spameri:elastic:move-type oldIndex productType newIndex newIndexAlias -c
26+
*/
27+
protected function configure() : void
28+
{
29+
$this
30+
->setName('spameri:elastic:move-type')
31+
->setDescription('Move type to new index to separate data and prepare for deprecation of types is ES.')
32+
->addArgument('indexFrom', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
33+
->addArgument('typeFrom', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
34+
->addArgument('indexTo', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
35+
->addArgument('aliasTo', \Symfony\Component\Console\Input\InputArgument::REQUIRED)
36+
->addArgument('typeTo', \Symfony\Component\Console\Input\InputArgument::OPTIONAL, 'Use only on old ElasticSearch', NULL)
37+
->addOption('allowClose', 'c', NULL,
38+
'Allows command to close index for data transfer. After data is transferred index is opened and resumes normal operations. When open it needs to check changed files after move and sync remaining.',
39+
TRUE
40+
)
41+
;
42+
}
43+
44+
protected function execute(
45+
\Symfony\Component\Console\Input\InputInterface $input
46+
, \Symfony\Component\Console\Output\OutputInterface $output
47+
)
48+
{
49+
$output->writeln('Starting');
50+
51+
$indexFrom = $input->getArgument('indexFrom');
52+
$typeFrom = $input->getArgument('typeFrom');
53+
$indexTo = $input->getArgument('indexTo');
54+
$aliasTo = $input->getArgument('aliasTo');
55+
$typeTo = $input->getOption('typeTo');
56+
$allowClose = $input->getOption('allowClose');
57+
58+
$this->migrate->setOutput($output);
59+
$this->migrate->execute($indexFrom, $typeFrom, $indexTo, $aliasTo, $typeTo, $allowClose);
60+
61+
$output->writeln('Done');
62+
}
63+
64+
}

src/Config/Elastic.neon

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,44 @@ services:
2626
search:
2727
class: Spameri\Elastic\Model\Search
2828

29+
scroll:
30+
class: Spameri\Elastic\Model\Scroll
31+
2932
delete:
3033
class: Spameri\Elastic\Model\Delete
3134

3235
deleteMultiple:
3336
class: Spameri\Elastic\Model\DeleteMultiple
3437

38+
indiceClose:
39+
class: Spameri\Elastic\Model\Indices\Close
40+
41+
indiceOpen:
42+
class: Spameri\Elastic\Model\Indices\Open
43+
44+
indiceGet:
45+
class: Spameri\Elastic\Model\Indices\Get
46+
47+
indiceGetMapping:
48+
class: Spameri\Elastic\Model\Indices\GetMapping
49+
50+
indicePutMapping:
51+
class: Spameri\Elastic\Model\Indices\PutMapping
52+
53+
indicePutSettings:
54+
class: Spameri\Elastic\Model\Indices\PutSettings
55+
56+
indicesCreate:
57+
class: Spameri\Elastic\Model\Indices\Create
58+
3559
serviceLocator:
3660
class: Spameri\Elastic\Model\ServiceLocator
3761

3862
mapping:
3963
class: Spameri\Elastic\Model\Mapping
4064

4165
userProvider:
42-
class: Spameri\Elastic\Model\UserProvider
66+
class: Spameri\Elastic\Model\NetteUserProvider
4367

4468
neonSettingsProvider:
4569
class: Spameri\Elastic\Settings\NeonSettingsProvider(%host%, %port%)
@@ -62,33 +86,82 @@ services:
6286
display:
6387
class: Spameri\Elastic\Model\ValidateMapping\Display
6488

89+
documentMigrateStatus:
90+
class: Spameri\Elastic\Model\TypeToNewIndex\DocumentMigrateStatus
91+
92+
migrate:
93+
class: Spameri\Elastic\Model\TypeToNewIndex\Migrate
94+
95+
modelDumpIndex:
96+
class: \Spameri\Elastic\Model\DumpIndex
97+
98+
restoreIndex:
99+
class: \Spameri\Elastic\Model\RestoreIndex
100+
65101
# ###
66102
# Commands
67103
# ###
68104

69105
createIndex:
70106
class: Spameri\Elastic\Commands\CreateIndex(%entities%)
71-
tags: [kdyby.console.command]
107+
tags:
108+
- kdyby.console.command
109+
- console.command
72110

73111
updateMapping:
74112
class: Spameri\Elastic\Commands\UpdateMapping(%entities%)
75-
tags: [kdyby.console.command]
113+
tags:
114+
- kdyby.console.command
115+
- console.command
76116

77117
deleteIndex:
78118
class: Spameri\Elastic\Commands\DeleteIndex
79-
tags: [kdyby.console.command]
119+
tags:
120+
- kdyby.console.command
121+
- console.command
80122

81123
addAlias:
82124
class: Spameri\Elastic\Commands\AddAlias
83-
tags: [kdyby.console.command]
125+
tags:
126+
- kdyby.console.command
127+
- console.command
84128

85129
removeAlias:
86130
class: Spameri\Elastic\Commands\RemoveAlias
87-
tags: [kdyby.console.command]
131+
tags:
132+
- kdyby.console.command
133+
- console.command
88134

89135
validateMappingCommand:
90136
class: Spameri\Elastic\Commands\ValidateMapping
91-
tags: [kdyby.console.command]
137+
tags:
138+
- kdyby.console.command
139+
- console.command
140+
141+
typeToNewIndex:
142+
class: Spameri\Elastic\Commands\TypeToNewIndex
143+
tags:
144+
- kdyby.console.command
145+
- console.command
146+
147+
dumpIndex:
148+
class: Spameri\Elastic\Commands\DumpIndex
149+
tags:
150+
- kdyby.console.command
151+
- console.command
152+
153+
loadDump:
154+
class: Spameri\Elastic\Commands\LoadDump
155+
tags:
156+
- kdyby.console.command
157+
- console.command
158+
159+
# ###
160+
# Spameri/ElasticQuery
161+
# ###
162+
163+
resultMapper:
164+
class: Spameri\ElasticQuery\Response\ResultMapper
92165

93166
# ###
94167
# Elastic/Elastic
@@ -99,11 +172,8 @@ services:
99172
setup:
100173
- setLogger(@elasticSearch.elasticPanelLogger)
101174

102-
constantProvider:
103-
class: Kdyby\DateTimeProvider\Provider\ConstantProvider(@elasticSearch.dateTime)
175+
dateTimeProvider:
176+
class: Spameri\Elastic\Provider\DateTimeProvider(@elasticSearch.dateTime)
104177

105178
dateTime:
106179
class: \DateTimeImmutable
107-
108-
resultMapper:
109-
class: Spameri\ElasticQuery\Response\ResultMapper

0 commit comments

Comments
 (0)