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:----e822KfA692+SNhzKhKeS0yfGkUwmWoxNYbwa+fL06l3KeGiyFHu0HrQTBJLaaO4j2fZS8ufWuE8Rfaxsoc7PXCzCBvIMS95niwzOB98uzCXPCAp+VrHEL5tn6xyfCIHMlkPdT9vywD/RtriKkeeMF4YR39MHzePkNjDGWmwPn3YdokcRtQUHrH/jNtq7owHOXnBVDi9vWPAT2Gyc8rUUvGLQI/1DsTRhdXA14VvM4cbWst392OKZnpm77l78GzVvfUVaR46avjZI2swg/Znxxu0H14mUd6da+Oh7oq8Knl6hyVbf8foUtooGDcT5Wgu5Q2GuKjNO5oxYEEeun9i9NF7DBSK6ljMUVDarC4AivW5Wfurt7PH0SnmRyK/wAzFzWBOZRQZMe3opJXitEhzirBpWIOUJU6eIsTYXLXURXz1ubWlitSdg50U/B6qRvHsAP5pevVU7pyRJ2TWD7IRtF4UoBHju2NkxSl8PzRFjQc1XvbxGnwdG82xZMb1B5hztN2haP7oYd8UQNxJiDhq5JM7oLkv7egqlOO7GyTdSSRbRwbd5wkQg8tFXch0fQdymTlvk9tqCHiJEAir4z43SFc+XAZoPEUI4VkrHooFreH9+Y2zty78975S07tM/e/pnQ/+wW7IirTQ1LCoEmlxAOMPyaSQQlNzObxBpt9YblOw=----ATTACHMENT:----MzUwOTQzMjM4MDk1MzE0MCAxOTc1NTA4NzM2MTg5MzgxIDY2MTQ5ODk3MjI2NTE5