feat: move departments from projects to companies

Departments now belong to a Company, not a Project.
- New migration: recreates settings_departments with company_id (migrates existing data)
- Department model: company_id FK, company() relation
- Company model: departments() hasMany relation
- ProjectSetting model: removes departments() relation
- Controller: dept methods now take Company instead of ProjectSetting
- Routes: department CRUD moves to companies/{company}/departments
- View: departments section appears on each company card (purple theme);
  project body is now locations-only (single column)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
ghassanandClaude Sonnet 4.6 committed 2026-05-26 18:26:27 +03:00
1 parent 9a268dc79b
commit 12e07480a0
7 files changed
+206 -153

No files matched your search

@@ -0,0 +1,47 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
// Recreate table with company_id instead of project_id (SQLite-safe)
Schema::create('settings_departments_new', function (Blueprint $table) {
$table->id();
$table->foreignId('company_id')->constrained('settings_companies')->onDelete('cascade');
$table->string('name');
$table->boolean('is_active')->default(true);
$table->timestamps();
});
// Migrate: map each department's project_id → that project's company_id
DB::statement('
INSERT INTO settings_departments_new (id, company_id, name, is_active, created_at, updated_at)
SELECT d.id, p.company_id, d.name, d.is_active, d.created_at, d.updated_at
FROM settings_departments d
LEFT JOIN settings_projects p ON p.id = d.project_id
WHERE p.company_id IS NOT NULL
');
Schema::drop('settings_departments');
Schema::rename('settings_departments_new', 'settings_departments');
}
public function down(): void
{
Schema::create('settings_departments_old', function (Blueprint $table) {
$table->id();
$table->foreignId('project_id')->constrained('settings_projects')->onDelete('cascade');
$table->string('name');
$table->boolean('is_active')->default(true);
$table->timestamps();
});
Schema::drop('settings_departments');
Schema::rename('settings_departments_old', 'settings_departments');
}
};