From d08f4c83470c25d35d24594bd73e4effdac191a0 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Tue, 19 Aug 2025 15:50:42 +0200 Subject: database migrations and models for users, devices, tokens --- bin/db-migrate | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 bin/db-migrate (limited to 'bin') diff --git a/bin/db-migrate b/bin/db-migrate new file mode 100755 index 0000000..784aadc --- /dev/null +++ b/bin/db-migrate @@ -0,0 +1,36 @@ +#!/bin/env php + +load(dirname(__DIR__) . "/.env"); + +$migrationsPath = dirname(__DIR__) . "/migrations"; +$migrations = scandir($migrationsPath, SCANDIR_SORT_ASCENDING); + +$appliedMigrations = []; +try { + Database::getInstance()->query("select name from migrations")->fetchAll(); +} catch (\PDOException $exception) { + echo "migrations table doesn't exist yet."; +} + +foreach ($migrations as $migration) { + if (in_array($migration, [".", ".."])) { + continue; + } + + if (in_array($migration, $appliedMigrations)) { + continue; + } + + $path = "$migrationsPath/$migration"; + include $path; + + Database::getInstance()->query("insert into migrations (name) values (:name)", ["name" => $migration]); +} -- cgit v1.2.3