-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigration-api.php
More file actions
41 lines (33 loc) · 1.2 KB
/
migration-api.php
File metadata and controls
41 lines (33 loc) · 1.2 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
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
Route::post('/api/migrate', function (Request $request) {
// Simple security check
$token = $request->input('token');
$expectedToken = env('MIGRATION_TOKEN', 'default-migration-token');
if ($token !== $expectedToken) {
Log::warning('Unauthorized migration attempt', ['ip' => $request->ip()]);
return response()->json(['error' => 'Unauthorized'], 401);
}
try {
// Run migrations
Artisan::call('migrate', ['--force' => true]);
$output = Artisan::output();
Log::info('Migrations completed via API', ['output' => $output]);
return response()->json([
'success' => true,
'message' => 'Migrations completed successfully',
'output' => $output
]);
} catch (\Exception $e) {
Log::error('Migration failed via API', [
'error' => $e->getMessage(),
'trace' => $e->getTraceAsString()
]);
return response()->json([
'success' => false,
'error' => $e->getMessage()
], 500);
}
});