blob: c166fcdf26fd7074ab8f601d944e0a654f12030a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#!/bin/env php
<?php
use App\Database;
use Symfony\Component\Dotenv\Dotenv;
require_once dirname(__DIR__) . "/vendor/autoload.php";
$dotenv = new Dotenv();
$dotenv->load(dirname(__DIR__) . "/.env");
$migrationsPath = dirname(__DIR__) . "/migrations";
$migrations = scandir($migrationsPath, SCANDIR_SORT_ASCENDING);
$appliedMigrations = [];
try {
$appliedMigrations = array_column(Database::getInstance()->query("select name from migrations")->fetchAll(), "name");
} catch (\PDOException $exception) {
echo "migrations table doesn't exist yet.";
}
foreach ($migrations as $migration) {
if (in_array($migration, [".", ".."])) {
continue;
}
$migrationName = basename($migration, ".php");
if (in_array($migrationName, $appliedMigrations)) {
continue;
}
$path = "$migrationsPath/$migration";
include $path;
Database::getInstance()->query("insert into migrations (name) values (:name)", ["name" => $migrationName]);
}
|