diff --git a/database/migrate.php b/database/migrate.php deleted file mode 100644 index 8e803f1..0000000 --- a/database/migrate.php +++ /dev/null @@ -1,16 +0,0 @@ -exec((string) file_get_contents(dirname(__DIR__) . '/database/schema.sql')); } return self::$pdo; } - public static function runMigrations(): array - { - if (self::$pdo === null) { - self::init(); - } - - $root = dirname(__DIR__); - - self::$pdo->exec( - "CREATE TABLE IF NOT EXISTS migrations ( - version TEXT PRIMARY KEY, - applied_at TEXT NOT NULL DEFAULT (datetime('now')) - )" - ); - - $applied = array_column(self::$pdo->query('SELECT version FROM migrations')->fetchAll(), 'version'); - - $files = glob($root . '/database/migrations/*.sql') ?: []; - sort($files); - - $newlyApplied = []; - - foreach ($files as $file) { - $version = basename($file); - - if (in_array($version, $applied, true)) { - continue; - } - - self::$pdo->beginTransaction(); - - try { - self::$pdo->exec((string) file_get_contents($file)); - - $stmt = self::$pdo->prepare('INSERT INTO migrations (version) VALUES (:version)'); - $stmt->execute(['version' => $version]); - - self::$pdo->commit(); - } catch (Throwable $e) { - self::$pdo->rollBack(); - throw $e; - } - - $newlyApplied[] = $version; - } - - return $newlyApplied; - } - private static function init(): void { $root = dirname(__DIR__);