1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
6
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
7
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
8
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
9
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
10
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
11
|
|
|
* THE SOFTWARE. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Ytake\LaravelCouchbase\Migrations; |
15
|
|
|
|
16
|
|
|
use Illuminate\Database\Schema\Blueprint; |
17
|
|
|
use Ytake\LaravelCouchbase\Schema\Builder; |
18
|
|
|
use Ytake\LaravelCouchbase\Query\Builder as QueryBuilder; |
19
|
|
|
use Ytake\LaravelCouchbase\Schema\Blueprint as CouchbaseBlueprint; |
20
|
|
|
use Illuminate\Database\Migrations\DatabaseMigrationRepository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class CouchbaseMigrationRepository |
24
|
|
|
* @codeCoverageIgnore |
25
|
|
|
* |
26
|
|
|
* @author Yuuki Takezawa<[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class CouchbaseMigrationRepository extends DatabaseMigrationRepository |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function log($file, $batch) |
34
|
|
|
{ |
35
|
|
|
$record = ['migration' => $file, 'batch' => $batch]; |
36
|
|
|
|
37
|
|
|
$builder = $this->table(); |
38
|
|
|
if ($builder instanceof QueryBuilder) { |
39
|
|
|
/** @var Builder */ |
40
|
|
|
$builder->key("{$file}:{$batch}")->insert($record); |
41
|
|
|
|
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
$builder->insert($record); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function createRepository() |
51
|
|
|
{ |
52
|
|
|
$schema = $this->getConnection()->getSchemaBuilder(); |
53
|
|
|
|
54
|
|
|
if ($schema instanceof Builder) { |
55
|
|
|
$schema->create($this->table, function (CouchbaseBlueprint $table) { |
56
|
|
|
$table->primaryIndex(); |
57
|
|
|
$table->index(['migration', 'batch'], 'migration_secondary_index'); |
58
|
|
|
}); |
59
|
|
|
|
60
|
|
|
return; |
61
|
|
|
} |
62
|
|
|
$schema->create($this->table, function (Blueprint $table) { |
63
|
|
|
$table->string('migration'); |
64
|
|
|
$table->integer('batch'); |
65
|
|
|
}); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|