-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** @var \SQLite3 $db */ | ||
require_once 'includes/connect_endpoint_crontabs.php'; | ||
|
||
$completedMigrations = []; | ||
|
||
$migrationTableExists = $db | ||
->query('SELECT name FROM sqlite_master WHERE type="table" AND name="migrations"') | ||
->fetchArray(SQLITE3_ASSOC) !== false; | ||
|
||
if ($migrationTableExists) { | ||
$migrationQuery = $db->query('SELECT migration FROM migrations'); | ||
while ($row = $migrationQuery->fetchArray(SQLITE3_ASSOC)) { | ||
$completedMigrations[] = $row['migration']; | ||
} | ||
} | ||
|
||
$allMigrations = glob('migrations/*.php'); | ||
$requiredMigrations = array_diff($allMigrations, $completedMigrations); | ||
|
||
if (count($requiredMigrations) === 0) { | ||
echo "No migrations to run.\n"; | ||
} | ||
|
||
foreach ($requiredMigrations as $migration) { | ||
require_once $migration; | ||
|
||
$stmtInsert = $db->prepare('INSERT INTO migrations (migration) VALUES (:migration)'); | ||
$stmtInsert->bindParam(':migration', $migration, SQLITE3_TEXT); | ||
$stmtInsert->execute(); | ||
|
||
echo sprintf("Migration %s completed successfully.\n", $migration); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
/** @noinspection PhpUndefinedVariableInspection */ | ||
$db->exec('CREATE TABLE IF NOT EXISTS migrations ( | ||
id INTEGER PRIMARY KEY, | ||
migration TEXT NOT NULL, | ||
migrated_at DATETIME DEFAULT CURRENT_TIMESTAMP | ||
)'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters