Skip to content

Commit 83bb467

Browse files
author
Vipul Singh
committed
fixed migration
1 parent 1e6cc07 commit 83bb467

16 files changed

Lines changed: 88 additions & 24 deletions

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ DB_CONNECTION=sqlite
2727
# DB_USERNAME=root
2828
# DB_PASSWORD=
2929

30-
SESSION_DRIVER=database
30+
SESSION_DRIVER=file
3131
SESSION_LIFETIME=120
3232
SESSION_ENCRYPT=false
3333
SESSION_PATH=/
3434
SESSION_DOMAIN=null
3535

3636
BROADCAST_CONNECTION=log
3737
FILESYSTEM_DISK=local
38-
QUEUE_CONNECTION=database
38+
QUEUE_CONNECTION=sync
3939

40-
CACHE_STORE=database
40+
CACHE_STORE=file
4141
# CACHE_PREFIX=
4242

4343
MEMCACHED_HOST=127.0.0.1

app/Http/Controllers/InstallController.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ public function run()
161161
$dbPath = database_path('database.sqlite');
162162
if (!file_exists($dbPath)) touch($dbPath);
163163
}
164-
// 2. Write .env (uses default key from .env.example so app can boot)
164+
// 2. Switch to production drivers (DB-backed) now that DB will exist
165+
$env = $this->setEnv($env, 'SESSION_DRIVER', 'database');
166+
$env = $this->setEnv($env, 'CACHE_STORE', 'database');
167+
$env = $this->setEnv($env, 'QUEUE_CONNECTION', 'database');
168+
165169
File::put(base_path('.env'), $env);
166170
$steps[] = ['name' => 'Create .env configuration', 'status' => 'success'];
167171

@@ -175,23 +179,33 @@ public function run()
175179

176180
// 4. Set DB config at runtime so migrations work without reloading .env
177181
$dbConn = $db['db_connection'] ?? 'sqlite';
178-
config(["database.default" => $dbConn]);
182+
config(['database.default' => $dbConn]);
179183
if ($dbConn === 'sqlite') {
180-
config(["database.connections.sqlite.database" => database_path('database.sqlite')]);
184+
$sqlitePath = database_path('database.sqlite');
185+
if (!file_exists($sqlitePath)) touch($sqlitePath);
186+
config(['database.connections.sqlite.database' => $sqlitePath]);
181187
} else {
182188
config([
183189
"database.connections.{$dbConn}.host" => $db['db_host'] ?? '127.0.0.1',
184190
"database.connections.{$dbConn}.port" => $db['db_port'] ?? '3306',
185191
"database.connections.{$dbConn}.database" => $db['db_database'] ?? 'coopbank',
186-
"database.connections.{$dbConn}.username" => $db['db_username'] ?? 'root',
187-
"database.connections.{$dbConn}.password" => $db['db_password'] ?? '',
192+
"database.connections.{$dbConn}.username" => $db['db_username'] ?? 'root',
193+
"database.connections.{$dbConn}.password" => $db['db_password'] ?? '',
188194
]);
189195
}
190-
DB::purge();
191-
DB::reconnect();
192196

193-
// Clear config cache
194-
try { Artisan::call('config:clear'); } catch (\Exception $e) { /* may fail if no cache exists */ }
197+
// Purge ALL cached connections and reconnect with new config
198+
DB::purge($dbConn);
199+
DB::purge('sqlite');
200+
DB::purge('mysql');
201+
DB::purge('pgsql');
202+
DB::reconnect($dbConn);
203+
204+
// Verify the connection works
205+
DB::connection($dbConn)->getPdo();
206+
207+
// Clear any cached config
208+
try { Artisan::call('config:clear'); } catch (\Exception $e) {}
195209
$steps[] = ['name' => 'Configure database connection', 'status' => 'success'];
196210

197211
// 4. Create storage symlink
@@ -202,15 +216,15 @@ public function run()
202216
$steps[] = ['name' => 'Create storage symlink', 'status' => 'skipped', 'note' => 'Already exists'];
203217
}
204218

205-
// 5. Run migrations
206-
Artisan::call('migrate', ['--force' => true]);
207-
$steps[] = ['name' => 'Run database migrations', 'status' => 'success'];
219+
// 5. Run migrations on the correct connection
220+
Artisan::call('migrate', ['--database' => $dbConn, '--force' => true]);
221+
$steps[] = ['name' => 'Run database migrations (' . $dbConn . ')', 'status' => 'success'];
208222

209-
// 6. Seed data
210-
Artisan::call('db:seed', ['--class' => 'RoleSeeder', '--force' => true]);
211-
Artisan::call('db:seed', ['--class' => 'CountrySeeder', '--force' => true]);
212-
Artisan::call('db:seed', ['--class' => 'CompanySetupSeeder', '--force' => true]);
213-
Artisan::call('db:seed', ['--class' => 'ScheduledTaskSeeder', '--force' => true]);
223+
// 6. Seed data (uses the default connection we just set)
224+
Artisan::call('db:seed', ['--class' => 'RoleSeeder', '--database' => $dbConn, '--force' => true]);
225+
Artisan::call('db:seed', ['--class' => 'CountrySeeder', '--database' => $dbConn, '--force' => true]);
226+
Artisan::call('db:seed', ['--class' => 'CompanySetupSeeder', '--database' => $dbConn, '--force' => true]);
227+
Artisan::call('db:seed', ['--class' => 'ScheduledTaskSeeder', '--database' => $dbConn, '--force' => true]);
214228
$steps[] = ['name' => 'Seed roles, countries, company setup, scheduled tasks', 'status' => 'success'];
215229

216230
// 7. Create admin user
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace App\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\File;
8+
9+
/**
10+
* Ensures the app can boot for the installer even without .env.
11+
* Auto-creates .env from .env.example if missing.
12+
*/
13+
class EnsureInstallable
14+
{
15+
public function handle(Request $request, Closure $next)
16+
{
17+
// If already installed, redirect away from installer
18+
if (File::exists(storage_path('installed'))) {
19+
return redirect('/');
20+
}
21+
22+
// Auto-create .env from .env.example if missing
23+
if (!File::exists(base_path('.env')) && File::exists(base_path('.env.example'))) {
24+
File::copy(base_path('.env.example'), base_path('.env'));
25+
}
26+
27+
return $next($request);
28+
}
29+
}

database/migrations/2026_03_24_133435_create_countries_table.php renamed to database/migrations/2026_03_24_133431_create_countries_table.php

File renamed without changes.

database/migrations/2026_03_24_133434_create_regions_table.php renamed to database/migrations/2026_03_24_133431_create_regions_table.php

File renamed without changes.

database/migrations/2026_03_24_133435_create_states_table.php renamed to database/migrations/2026_03_24_133432_create_states_table.php

File renamed without changes.

database/migrations/2026_03_24_133435_create_cities_table.php renamed to database/migrations/2026_03_24_133433_create_cities_table.php

File renamed without changes.

database/migrations/2026_03_24_133447_create_customers_table.php renamed to database/migrations/2026_03_24_133445_create_customers_table.php

File renamed without changes.

database/migrations/2026_03_24_133447_create_share_accounts_table.php renamed to database/migrations/2026_03_24_133445_create_share_accounts_table.php

File renamed without changes.

database/migrations/2026_03_24_133447_create_bank_accounts_table.php renamed to database/migrations/2026_03_24_133446_create_bank_accounts_table.php

File renamed without changes.

0 commit comments

Comments
 (0)