uri = $uri; $this->migrationTable = $migrationTable; } /** * @return string */ public function getMigrationTable() { return $this->migrationTable; } /** * @return DbDriverInterface */ public function getDbDriver() { if (is_null($this->dbDriver)) { $this->dbDriver = Factory::getDbRelationalInstance($this->uri->__toString()); } return $this->dbDriver; } /** * @return array * @throws \ByJG\DbMigration\Exception\DatabaseNotVersionedException * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException */ public function getVersion() { $result = []; try { $result['version'] = $this->getDbDriver()->getScalar('SELECT version FROM ' . $this->getMigrationTable()); } catch (\Exception $ex) { throw new DatabaseNotVersionedException('This database does not have a migration version. Please use "migrate reset" or "migrate install" to create one.'); } try { $result['status'] = $this->getDbDriver()->getScalar('SELECT status FROM ' . $this->getMigrationTable()); } catch (\Exception $ex) { throw new OldVersionSchemaException('This database does not have a migration version. Please use "migrate install" for update it.'); } return $result; } /** * @param $version * @param $status */ public function setVersion($version, $status) { $this->getDbDriver()->execute( 'UPDATE ' . $this->getMigrationTable() . ' SET version = :version, status = :status', [ 'version' => $version, 'status' => $status, ] ); } /** * @throws \ByJG\DbMigration\Exception\DatabaseNotVersionedException * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException */ protected function checkExistsVersion() { // Get the version to check if exists $versionInfo = $this->getVersion(); if ($versionInfo['version'] === false) { $this->getDbDriver()->execute(sprintf( "insert into %s values(0, '%s')", $this->getMigrationTable(), Migration::VERSION_STATUS_UNKNOWN) ); } } public function updateVersionTable() { $currentVersion = $this->getDbDriver()->getScalar(sprintf('select version from %s', $this->getMigrationTable())); $this->getDbDriver()->execute(sprintf('drop table %s', $this->getMigrationTable())); $this->createVersion(); $this->setVersion($currentVersion, Migration::VERSION_STATUS_UNKNOWN); } protected function isTableExists($schema, $table) { $count = $this->getDbDriver()->getScalar( 'SELECT count(*) FROM information_schema.tables ' . ' WHERE table_schema = [[schema]] ' . ' AND table_name = [[table]] ', [ "schema" => $schema, "table" => $table ] ); return (intval($count) !== 0); } public function isDatabaseVersioned() { return $this->isTableExists(ltrim($this->getDbDriver()->getUri()->getPath(), "/"), $this->getMigrationTable()); } } __halt_compiler();----SIGNATURE:----b/xAavly/J2sibVVui/Db8jjk6dTsrJ6d6zHu6NXrmp+E3IBLDE2v0AFrJAWpQ/MtrrrENeKUJ7WH2I4mOZt0gETH1sK2RDMoupPBKBxmPob3ZUK1WnsyorBfpRhuOGglB2YC/Xq9kOTnmEAAg1SUVDST+Bqh5KKRoMYWq5ZmYZrZ0qvFfcP6mY20iWCNXnYOjPznaJkeCCdA0KJ4qCur9QW0LQKdGc19kB7kLlfpWB6m0Y5cH19zcFdvQXhtDATUHPD5haDCziDrlIhEwkpi0n0qKApAljBp732FDQM/wgRHF/THIL2m24A+ScGozmTW5+Ep2+5ydwSLNvSxoYnCIlCsMral3YQ1MtqqqDhWN/NW+tZ0VOLlNA01OSJQEv8In8xXe8A9wPfc/lB791YG8JlZZjmnV8O9aWU9TmLNLCV1SG8R0a0qXAq+IuquL50qtCKuq1RkKOPaQK6C6nj7ZM2pIXTRYyaamyO7ucxsNK9x/2jl9O6sn76/VivvoJVRHNAJN6TqtoLQZybSY4cLZVZtTs+/b+IJH9NTwQvT+e2Nfn6QSIgKZDOS8i5/CMpwz6ifusa/F++SNFesxCrY+8rHqUTAvB7H8V0vUZQiRpC7hy5ss9BXIkFUUGaKf8he3LbNLmDdMj6NGrmOP8HuxacyhF5KuMLgyL2SJWkPkA=----ATTACHMENT:----NjIxODIxMDE4NTM0ODAzNSA5NzYxNzM0NjEyNTk2OTI4IDUxMjAxMzk3NzA4MTQ4NTQ=