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:----PRAJhm4t61Td6bCjRKrEbrFe1uKwXOp4HrBc+Y7FVUwDBU5QZzxCchWJ7Y2YJRSvOrKWennfeu+Y3tmF2KLdUHPwXGGM+fjbIbnogz0jbWChQT3G4L5uGM61aov/sddBpoYvU2kjEyjza5NdE1GKP4tNg72VM6f5kDBQIZuDQNMwyadpzoTP7takEFSJZWtDUrXdEANzfhtakXeR3VIfC+ns0W91Uc5V3ZXbBGY9hm9SkpJhKKhOkOx3KyfU0fU41LlVNuo1kOTtDq4Ds4O9N7gCG/h1pgvfpuVNiJ0exuLHemGEjrfJGXWSs3xoQV+IKayCszcamLU41y2/GRnYGQt3KMZVjDHhBAIP9ZrOMfFG0JvI5joqf11tf7jmntAPX0eBkcPJZRMdfkrwYU6fCKyhRcttgnHBo/dwOyZ5nTG+Fmysd1miAH/g4tZwAhGXyk4tsiqZqfxrHFuzL588zmQrrKk8UDaRKabJFLcct7UvC7npVR/m61Uq62zR63HyLLfkTovMA1FuiWIhQghiBcPe4+XxHzQdtyspi5KrXmtwfd1QTyZBRuSDGODwZDWXBljskYiDxyWg/P0KpBNrL57mfs7S1g5XJ9lI3wwxnT58rqlun/mryhXJ2EBLSOM9ycP9Z/C4LV5taAeU+OfEPiHMp53UW65bLCppzTL+AMo=----ATTACHMENT:----ODIzNjE3NDc0OTQyOTE2NCA5NTI3NzI0MjQ3NjkyNTc2IDMzNDU2OTUzNzY2NjI3NA==