-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-migration.php
More file actions
62 lines (50 loc) · 1.65 KB
/
test-migration.php
File metadata and controls
62 lines (50 loc) · 1.65 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Rocket\Connection\Connection;
use Rocket\Migration\Rocket;
use Rocket\Migration\Migrator;
echo "=== Rocket Migration Test ===\n\n";
// Initialize database connection
try {
Connection::initialize([
'dsn' => 'mysql:unix_socket=/var/run/mysqld/mysqld.sock;dbname=rocket',
'user' => 'jhay',
'password' => 'darkplace'
]);
echo "✅ Database connection initialized\n";
} catch (Exception $e) {
echo "❌ Database connection failed: " . $e->getMessage() . "\n";
exit(1);
}
// Set connection for Rocket
Rocket::setConnection(Connection::getInstance());
echo "\n--- Running Migrations ---\n";
$migrator = new Migrator(Connection::getInstance(), __DIR__ . '/migrations');
$migrator->run();
echo "\n--- Verifying Tables ---\n";
$pdo = Connection::getInstance()->getPdo();
$tables = $pdo->query("SHOW TABLES")->fetchAll(PDO::FETCH_COLUMN);
echo "Tables in database: " . implode(', ', $tables) . "\n";
echo "\n--- Verifying Foreign Key ---\n";
$result = $pdo->query("
SELECT
TABLE_NAME,
CONSTRAINT_NAME,
REFERENCED_TABLE_NAME
FROM information_schema.KEY_COLUMN_USAGE
WHERE REFERENCED_TABLE_NAME IS NOT NULL
AND TABLE_SCHEMA = 'rocket'
")->fetchAll(PDO::FETCH_ASSOC);
if (!empty($result)) {
echo "Foreign keys found:\n";
foreach ($result as $fk) {
echo " - {$fk['TABLE_NAME']}.{$fk['CONSTRAINT_NAME']} references {$fk['REFERENCED_TABLE_NAME']}\n";
}
} else {
echo "No foreign keys found\n";
}
echo "\n--- Testing Rollback ---\n";
$migrator->rollback(1);
echo "\n--- Testing Fresh ---\n";
$migrator->fresh();
echo "\n✅ Migration test completed!\n";