Files
transfer.tapee.ac.th/migrate_oauth.php
T
pongpon pitisuk 72701ad58c Initial import
2026-06-25 16:49:13 +07:00

46 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/db.php';
try {
$db = getDB();
// Users table
try {
$db->exec("ALTER TABLE users ADD COLUMN google_id VARCHAR(255) DEFAULT NULL AFTER email");
echo "✅ Added google_id to users table\n";
} catch (PDOException $e) {
if (strpos($e->getMessage(), 'Duplicate column') !== false) {
echo "️ google_id already exists in users\n";
} else {
throw $e;
}
}
// Students table
$columns = [
'email' => "ALTER TABLE students ADD COLUMN email VARCHAR(255) DEFAULT NULL AFTER name_en",
'password' => "ALTER TABLE students ADD COLUMN password VARCHAR(255) DEFAULT NULL AFTER email",
'google_id' => "ALTER TABLE students ADD COLUMN google_id VARCHAR(255) DEFAULT NULL AFTER password",
'advisor_id' => "ALTER TABLE students ADD COLUMN advisor_id INT DEFAULT NULL AFTER curriculum_id",
'previous_qualification' => "ALTER TABLE students ADD COLUMN previous_qualification VARCHAR(255) DEFAULT NULL AFTER graduated_institution",
];
foreach ($columns as $name => $sql) {
try {
$db->exec($sql);
echo "✅ Added $name to students table\n";
} catch (PDOException $e) {
if (strpos($e->getMessage(), 'Duplicate column') !== false) {
echo "$name already exists in students\n";
} else {
throw $e;
}
}
}
echo "\n✅ Migration completed successfully!\n";
} catch (Exception $e) {
die("❌ Error: " . $e->getMessage() . "\n");
}