getPath()); $dbDriver = static::getDbDriverWithoutDatabase($uri); static::createDatabaseIfNotExists($dbDriver, $database); } protected static function getDbDriverWithoutDatabase(UriInterface $uri) { $customUri = new Uri($uri->__toString()); return Factory::getDbRelationalInstance($customUri->withPath('/postgres')->__toString()); } /** * @param \ByJG\AnyDataset\Db\DbDriverInterface $dbDriver * @param $database */ protected static function createDatabaseIfNotExists($dbDriver, $database) { $currentDbName = $dbDriver->getScalar( "SELECT datname FROM pg_catalog.pg_database WHERE lower(datname) = lower(:dbname)", ['dbname' => $database] ); if (empty($currentDbName)) { $dbDriver->execute("CREATE DATABASE $database WITH encoding=\"UTF8\";"); } } public function createDatabase() { $database = preg_replace('~^/~', '', $this->getDbDriver()->getUri()->getPath()); static::createDatabaseIfNotExists($this->getDbDriver(), $database); } public function dropDatabase() { $iterator = $this->getDbDriver()->getIterator( "select 'drop table if exists \"' || tablename || '\" cascade;' command from pg_tables where schemaname = 'public';" ); foreach ($iterator as $singleRow) { $this->getDbDriver()->execute($singleRow->get('command')); } } /** * @throws \ByJG\DbMigration\Exception\DatabaseNotVersionedException * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException */ public function createVersion() { $this->getDbDriver()->execute('CREATE TABLE IF NOT EXISTS ' . $this->getMigrationTable() . ' (version int, status varchar(20), PRIMARY KEY (version))'); $this->checkExistsVersion(); } public function executeSql($sql) { $statements = preg_split("/;(\r\n|\r|\n)/", $sql); foreach ($statements as $sql) { $this->executeSqlInternal($sql); } } protected function executeSqlInternal($sql) { if (empty(trim($sql))) { return; } $this->getDbDriver()->execute($sql); } public function isDatabaseVersioned() { return $this->isTableExists('public', $this->getMigrationTable()); } } __halt_compiler();----SIGNATURE:----GWllZjjscEYF8hO7qhvXmrthA2CaPfMqDd6pVSYYtrfwcFSJ6hpVvBitUP0n0mg/mTJpqckc9q9+xv/03tUejMkKInj/E/1KXr7DzZmFmZ225Hr+rNjLPD5WKZ9gjLgbSJV3YaaG8ixGsvpLuY3FtCM8rUr3hAuScjTV70cwTLIGmc/z2wA00l0ek6AvLRCM/8vI2G6sgnajE3wEhRvliTQVkzv/zD4m1ub8usWS3DG+w6z8UO2gl8pe+lKELRPCS29dyltRB47YNXOKHTrsPb4f63aC7XhicM7/KFenmr3r0Zl9oQQaqye5HVGy+fyEen26An9JCcp5ud+KI9KO7Yn64WLkV27liUniS2onAUuUpWzhGmHfbJTu7lBfARS1sm1h8k23jj70gCQVw6DjUiySagSkVg3k+3QlV5MymvWzrR8DrB/Fmnp5iiFvQ8CZPA3VpOStGx0CIXo0f95AWO1LPApaiIkm/Qn9aC+jy974Yyd20u5tRF5Wx1vghMriHJAYwwQ2eC7kJLjI8Hij/qBYrGg4RXuwmgIfPyrd76Clln/PH//fhmU5fl0fGL5CHiMqJi0FNSdxbtFp9HmdbQM1WB5V/3mXHA7NjwQrPC4m+3lbdATCdplTEOg1vykk8X4fQgHbzRgeOTyUebhI+hYt1lJatYVLZ/5S1cC6DC0=----ATTACHMENT:----NTAxMTA1NDI3Mzk4NTQ1NCA3NDM1ODg0OTk0MTYxMTAzIDIzNzY0NTQyNzA0MTA5Nzc=