diff --git a/bin/migrate-sqlite-to-pg.php b/bin/migrate-sqlite-to-pg.php index 7a779fb..5554398 100644 --- a/bin/migrate-sqlite-to-pg.php +++ b/bin/migrate-sqlite-to-pg.php @@ -13,7 +13,14 @@ if (!$pgUrl) { $sqlite = new PDO('sqlite:' . $sqlitePath); $sqlite->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -$pg = new PDO(preg_replace('#^postgresql://#', 'pgsql://', $pgUrl)); +// PDO pgsql akzeptiert keine // URLs -> DSN-Form +preg_match('#^[a-z+]+://([^:@/]*)(?::([^@/]*))?@([^:/?]*)(?::(\d+))?/([^?]*)(?:\?(.*))?$#', $pgUrl, $m); +[$authUser, $authPass, $host, $port, $dbname] = [$m[1] ?? 'essens', $m[2] ?? '', $m[3] ?? 'localhost', $m[4] ?? '5432', $m[5] ?? 'essens']; +$pg = new PDO( + sprintf('pgsql:host=%s;port=%s;dbname=%s;user=%s;password=%s', $host, $port, $dbname, $authUser, $authPass), + $authUser, + $authPass, +); $pg->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $copy = $pg->beginTransaction();