Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automated: Add CODEOWNERS file for team @deseretdigital/architecture #58

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# FILE GENERATRED BY gendoc-update-codeowners-and-properties

# This file is used to define code owners for the repository.
# The format is:
# <scope> <team>
# where scope is the directory or file to which the team is assigned.
# For example:
# * @team
* @deseretdigital/architecture
7 changes: 1 addition & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "doesntmattr/mongodb-migrations",
"name": "deseretdigital/mongodb-migrations",
"type": "library",
"description": "Managed Database Migrations for MongoDB",
"keywords": ["doesntmattr", "antimattr", "database", "doctrine", "migration", "mongodb"],
Expand Down Expand Up @@ -36,11 +36,6 @@
]
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"archive": {
"exclude": ["bin", "demo", "tests", "*phpunit.xml"]
}
Expand Down
19 changes: 15 additions & 4 deletions src/AntiMattr/MongoDB/Migrations/AbstractMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
use AntiMattr\MongoDB\Migrations\Exception\AbortException;
use AntiMattr\MongoDB\Migrations\Exception\IrreversibleException;
use AntiMattr\MongoDB\Migrations\Exception\SkipException;
use Doctrine\MongoDB\Collection;
use Doctrine\MongoDB\Database;
use \MongoDB\Collection;
use \MongoDB\Database;
use Doctrine\ODM\MongoDB\DocumentManager;

/**
* @author Matthew Fitzgerald <matthewfitz@gmail.com>
Expand Down Expand Up @@ -56,15 +57,15 @@ abstract public function up(Database $db);
abstract public function down(Database $db);

/**
* @param \Doctrine\MongoDB\Collection
* @param \MongoDB\Collection
*/
protected function analyze(Collection $collection)
{
$this->version->analyze($collection);
}

/**
* @param \Doctrine\MongoDB\Database
* @param \MongoDB\Database
* @param string $filename
*/
protected function executeScript(Database $db, $filename)
Expand Down Expand Up @@ -142,6 +143,16 @@ public function skipIf($condition, $message = '')
}
}

/**
* Return document manager or null
*
* @return DocumentManager|null
*/
public function getDocumentManager() : ?DocumentManager
{
return $this->configuration->getDocumentManager();
}

public function preUp(Database $db)
{
}
Expand Down
23 changes: 12 additions & 11 deletions src/AntiMattr/MongoDB/Migrations/Collection/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

namespace AntiMattr\MongoDB\Migrations\Collection;

use Doctrine\MongoDB\Collection;
use \MongoDB\Collection;
use Exception;
use MongoDB\Database;

/**
* @author Matthew Fitzgerald <matthewfitz@gmail.com>
Expand Down Expand Up @@ -42,7 +43,7 @@ class Statistics
];

/**
* @var \Doctrine\MongoDB\Collection
* @var \MongoDB\Collection
*/
private $collection;

Expand All @@ -56,16 +57,21 @@ class Statistics
*/
private $after = [];

public function setDatabase(Database $database)
{
$this->database = $database;
}

/**
* @param \Doctrine\MongoDB\Collection
* @param \MongoDB\Collection
*/
public function setCollection(Collection $collection)
{
$this->collection = $collection;
}

/**
* @return \Doctrine\MongoDB\Collection
* @return \MongoDB\Collection
*/
public function getCollection()
{
Expand Down Expand Up @@ -115,21 +121,16 @@ public function getAfter()
*/
protected function getCollectionStats()
{
$database = $this->collection->getDatabase();
$name = $this->collection->getName();
$name = $this->collection->getCollectionName();

if (!$data = $database->command(['collStats' => $name])) {
if (!$data = $this->database->command(['collStats' => $name])) {
$message = sprintf(
'Statistics not found for collection %s',
$name
);
throw new Exception($message);
}

if (isset($data['errmsg'])) {
throw new Exception($data['errmsg']);
}

return $data;
}
}
72 changes: 45 additions & 27 deletions src/AntiMattr/MongoDB/Migrations/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@
use AntiMattr\MongoDB\Migrations\Exception\UnknownVersionException;
use AntiMattr\MongoDB\Migrations\OutputWriter;
use AntiMattr\MongoDB\Migrations\Version;
use Doctrine\MongoDB\Connection;
use Doctrine\MongoDB\Database;
use MongoDB\Client;
use Doctrine\ODM\MongoDB\DocumentManager;

/**
* @author Matthew Fitzgerald <matthewfitz@gmail.com>
*/
class Configuration
{
/**
* @var \Doctrine\MongoDB\Collection
* @var \MongoDB\Collection
*/
private $collection;

/**
* @var \Doctrine\MongoDB\Connection
* @var \MongoDB\Client
*/
private $connection;

/**
* @var \Doctrine\MongoDB\Database
* @var \MongoDB\Database
*/
private $database;

/**
* @var \Doctrine\MongoDB\Connection
* @var DocumentManager
*/
private $migrationsDatabase;
private $documentManager;

/**
* The migration database name to track versions in.
Expand Down Expand Up @@ -109,10 +109,10 @@ class Configuration
private $file;

/**
* @param \Doctrine\MongoDB\Connection $connection
* @param \MongoDB\Client $connection
* @param \AntiMattr\MongoDB\Migrations\OutputWriter $outputWriter
*/
public function __construct(Connection $connection, OutputWriter $outputWriter = null)
public function __construct(Client $connection, OutputWriter $outputWriter = null)
{
$this->connection = $connection;
if (null === $outputWriter) {
Expand Down Expand Up @@ -156,7 +156,7 @@ public function getAvailableVersions()
}

/**
* @return \Doctrine\MongoDB\Collection
* @return \MongoDB\Collection
*/
public function getCollection()
{
Expand All @@ -170,17 +170,17 @@ public function getCollection()
}

/**
* @return \Doctrine\MongoDB\Connection
* @return \MongoDB\Client
*/
public function getConnection()
{
return $this->connection;
}

/**
* @return \Doctrine\MongoDB\Database
* @return \MongoDB\Database
*/
public function getDatabase(): ?Database
public function getDatabase(): ?\MongoDB\Database
{
if (isset($this->database)) {
return $this->database;
Expand All @@ -191,6 +191,26 @@ public function getDatabase(): ?Database
return $this->database;
}

/**
* Return document manager
*
* @return DocumentManager
*/
public function getDocumentManager(): ?DocumentManager
{
return $this->documentManager;
}

/**
* Set document manager
*
* @param DocumentManager $documentManager
*/
public function setDocumentManager(DocumentManager $documentManager)
{
$this->documentManager = $documentManager;
}

/**
* Get the array of registered migration versions.
*
Expand Down Expand Up @@ -347,17 +367,18 @@ public function getMigratedTimestamp($version): int
['v' => $version]
);

if (!$cursor->count()) {
$result = $cursor->toArray();
if (!count($result)) {
throw new UnknownVersionException($version);
}

if ($cursor->count() > 1) {
if (count($result) > 1) {
throw new \DomainException(
'Unexpected duplicate version records in the database'
);
}

$returnVersion = $cursor->getNext();
$returnVersion = $result[0];

// Convert to normalised timestamp
$ts = new Timestamp($returnVersion['t']);
Expand Down Expand Up @@ -408,9 +429,7 @@ public function getNumberOfExecutedMigrations()
{
$this->createMigrationCollection();

$cursor = $this->getCollection()->find();

return $cursor->count();
return $this->getCollection()->countDocuments();
}

/**
Expand Down Expand Up @@ -560,17 +579,16 @@ public function getCurrentVersion()

$cursor = $this->getCollection()
->find(
['v' => ['$in' => $migratedVersions]]
)
->sort(['v' => -1])
->limit(1);
['v' => ['$in' => $migratedVersions]],
['sort' => ['v' => -1], 'limit' => 1]
);

if (0 === $cursor->count()) {
$versions = $cursor->toArray();
if (0 === \count($versions)) {
return '0';
}

$version = $cursor->getNext();

$version = $versions[0];
return $version['v'];
}

Expand Down Expand Up @@ -598,7 +616,7 @@ public function createMigrationCollection()

if (true !== $this->migrationCollectionCreated) {
$collection = $this->getCollection();
$collection->ensureIndex(['v' => -1], ['name' => 'version', 'unique' => true]);
$collection->createIndex(['v' => -1], ['name' => 'version', 'unique' => true]);
$this->migrationCollectionCreated = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace AntiMattr\MongoDB\Migrations\Configuration;

use AntiMattr\MongoDB\Migrations\OutputWriter;
use Doctrine\MongoDB\Connection;
use MongoDB\Client;
use Symfony\Component\Yaml\Yaml;

/**
Expand All @@ -23,7 +23,7 @@
class ConfigurationBuilder
{
/**
* @var \Doctrine\MongoDB\Connection
* @var \MongoDB\Client
*/
private $connection;

Expand Down Expand Up @@ -64,11 +64,11 @@ public static function create(): ConfigurationBuilder
}

/**
* @param Connection $connection
* @param Client $connection
*
* @return ConfigurationBuilder
*/
public function setConnection(Connection $connection): ConfigurationBuilder
public function setConnection(Client $connection): ConfigurationBuilder
{
$this->connection = $connection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use AntiMattr\MongoDB\Migrations\Configuration\Configuration;
use AntiMattr\MongoDB\Migrations\Configuration\ConfigurationBuilder;
use AntiMattr\MongoDB\Migrations\OutputWriter;
use Doctrine\MongoDB\Connection;
use MongoDB\Client;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -98,15 +98,15 @@ protected function getMigrationConfiguration(
/**
* @param InputInterface $input
*
* @return Connection
* @return Client
*/
protected function getDatabaseConnection(InputInterface $input): Connection
protected function getDatabaseConnection(InputInterface $input): Client
{
// Default to document manager helper set
if ($this->getApplication()->getHelperSet()->has('dm')) {
return $this->getHelper('dm')
->getDocumentManager()
->getConnection();
->getClient();
}

// PHP array file
Expand Down Expand Up @@ -136,7 +136,7 @@ protected function getDatabaseConnection(InputInterface $input): Connection
/**
* @param array $params
*
* @return \Doctrine\MongoDB\Connection
* @return \MongoDB\Client
*/
protected function createConnection($params)
{
Expand Down Expand Up @@ -166,6 +166,6 @@ protected function createConnection($params)
$options = $params['options'];
}

return new Connection($server, $options);
return new Client($server, $options);
}
}
Loading