Primo commit
This commit is contained in:
43
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
43
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignId('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('sessions');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
};
|
||||
65
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
65
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
Schema::dropIfExists('cache');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('settings', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('congregazione_nome')->nullable();
|
||||
$table->string('logo_path')->nullable();
|
||||
$table->unsignedInteger('giorni_giacenza_da_assegnare')->default(120);
|
||||
$table->unsignedInteger('giorni_giacenza_prioritari')->default(180);
|
||||
$table->unsignedInteger('giorni_per_smarrito')->default(120);
|
||||
$table->unsignedInteger('home_limit_list')->default(10);
|
||||
$table->unsignedInteger('audit_retention_days')->default(730);
|
||||
$table->boolean('setup_completed')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('settings');
|
||||
}
|
||||
};
|
||||
23
database/migrations/2024_01_01_000020_create_zone_table.php
Normal file
23
database/migrations/2024_01_01_000020_create_zone_table.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('zone', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nome');
|
||||
$table->boolean('attivo')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('zone');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tipologie', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('nome');
|
||||
$table->boolean('attivo')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tipologie');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('proclamatori', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->text('nome'); // encrypted at application level
|
||||
$table->text('cognome'); // encrypted at application level
|
||||
$table->boolean('attivo')->default(true);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('proclamatori');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('territori', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('numero')->unique();
|
||||
$table->foreignId('zona_id')->nullable()->constrained('zone')->nullOnDelete();
|
||||
$table->foreignId('tipologia_id')->nullable()->constrained('tipologie')->nullOnDelete();
|
||||
$table->text('note')->nullable();
|
||||
$table->text('confini')->nullable();
|
||||
$table->string('pdf_path')->nullable();
|
||||
$table->boolean('attivo')->default(true);
|
||||
$table->boolean('prioritario')->default(false);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('territori');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('anni_teocratici', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('label')->unique(); // e.g. "2025-2026"
|
||||
$table->date('start_date');
|
||||
$table->date('end_date');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('anni_teocratici');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('campagne', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->date('start_date');
|
||||
$table->date('end_date');
|
||||
$table->string('descrizione');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('campagne');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('assegnazioni', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('territorio_id')->constrained('territori')->restrictOnDelete();
|
||||
$table->foreignId('proclamatore_id')->constrained('proclamatori')->restrictOnDelete();
|
||||
$table->foreignId('anno_teocratico_id')->constrained('anni_teocratici')->restrictOnDelete();
|
||||
$table->date('assigned_at');
|
||||
$table->date('returned_at')->nullable();
|
||||
$table->boolean('counted_in_campaign')->nullable();
|
||||
$table->foreignId('campaign_id')->nullable()->constrained('campagne')->nullOnDelete();
|
||||
$table->text('note')->nullable();
|
||||
$table->foreignId('created_by')->constrained('users')->restrictOnDelete();
|
||||
$table->foreignId('returned_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
// Composite indexes for performance
|
||||
$table->index(['territorio_id', 'returned_at']);
|
||||
$table->index(['proclamatore_id', 'returned_at']);
|
||||
$table->index(['anno_teocratico_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('assegnazioni');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$teams = config('permission.teams');
|
||||
$tableNames = config('permission.table_names');
|
||||
$columnNames = config('permission.column_names');
|
||||
$pivotRole = $columnNames['role_pivot_key'] ?? 'role_id';
|
||||
$pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id';
|
||||
|
||||
throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
|
||||
throw_if($teams && empty($columnNames['team_foreign_key'] ?? null), Exception::class, 'Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
|
||||
|
||||
Schema::create($tableNames['permissions'], static function (Blueprint $table) {
|
||||
// $table->engine('InnoDB');
|
||||
$table->bigIncrements('id'); // permission id
|
||||
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
|
||||
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['name', 'guard_name']);
|
||||
});
|
||||
|
||||
Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) {
|
||||
// $table->engine('InnoDB');
|
||||
$table->bigIncrements('id'); // role id
|
||||
if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing
|
||||
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
|
||||
$table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index');
|
||||
}
|
||||
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
|
||||
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
|
||||
$table->timestamps();
|
||||
if ($teams || config('permission.testing')) {
|
||||
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
|
||||
} else {
|
||||
$table->unique(['name', 'guard_name']);
|
||||
}
|
||||
});
|
||||
|
||||
Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) {
|
||||
$table->unsignedBigInteger($pivotPermission);
|
||||
|
||||
$table->string('model_type');
|
||||
$table->unsignedBigInteger($columnNames['model_morph_key']);
|
||||
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
|
||||
|
||||
$table->foreign($pivotPermission)
|
||||
->references('id') // permission id
|
||||
->on($tableNames['permissions'])
|
||||
->onDelete('cascade');
|
||||
if ($teams) {
|
||||
$table->unsignedBigInteger($columnNames['team_foreign_key']);
|
||||
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
|
||||
|
||||
$table->primary([$columnNames['team_foreign_key'], $pivotPermission, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_permissions_permission_model_type_primary');
|
||||
} else {
|
||||
$table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_permissions_permission_model_type_primary');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) {
|
||||
$table->unsignedBigInteger($pivotRole);
|
||||
|
||||
$table->string('model_type');
|
||||
$table->unsignedBigInteger($columnNames['model_morph_key']);
|
||||
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
|
||||
|
||||
$table->foreign($pivotRole)
|
||||
->references('id') // role id
|
||||
->on($tableNames['roles'])
|
||||
->onDelete('cascade');
|
||||
if ($teams) {
|
||||
$table->unsignedBigInteger($columnNames['team_foreign_key']);
|
||||
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');
|
||||
|
||||
$table->primary([$columnNames['team_foreign_key'], $pivotRole, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_roles_role_model_type_primary');
|
||||
} else {
|
||||
$table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_roles_role_model_type_primary');
|
||||
}
|
||||
});
|
||||
|
||||
Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) {
|
||||
$table->unsignedBigInteger($pivotPermission);
|
||||
$table->unsignedBigInteger($pivotRole);
|
||||
|
||||
$table->foreign($pivotPermission)
|
||||
->references('id') // permission id
|
||||
->on($tableNames['permissions'])
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->foreign($pivotRole)
|
||||
->references('id') // role id
|
||||
->on($tableNames['roles'])
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary');
|
||||
});
|
||||
|
||||
app('cache')
|
||||
->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
|
||||
->forget(config('permission.cache.key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$tableNames = config('permission.table_names');
|
||||
|
||||
throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
|
||||
|
||||
Schema::drop($tableNames['role_has_permissions']);
|
||||
Schema::drop($tableNames['model_has_roles']);
|
||||
Schema::drop($tableNames['model_has_permissions']);
|
||||
Schema::drop($tableNames['roles']);
|
||||
Schema::drop($tableNames['permissions']);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateActivityLogTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->create(config('activitylog.table_name'), function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('log_name')->nullable();
|
||||
$table->text('description');
|
||||
$table->nullableMorphs('subject', 'subject');
|
||||
$table->nullableMorphs('causer', 'causer');
|
||||
$table->json('properties')->nullable();
|
||||
$table->timestamps();
|
||||
$table->index('log_name');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->dropIfExists(config('activitylog.table_name'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddEventColumnToActivityLogTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
|
||||
$table->string('event')->nullable()->after('subject_type');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
|
||||
$table->dropColumn('event');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddBatchUuidColumnToActivityLogTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
|
||||
$table->uuid('batch_uuid')->nullable()->after('properties');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
Schema::connection(config('activitylog.database_connection'))->table(config('activitylog.table_name'), function (Blueprint $table) {
|
||||
$table->dropColumn('batch_uuid');
|
||||
});
|
||||
}
|
||||
}
|
||||
16
database/seeders/DatabaseSeeder.php
Normal file
16
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
RolesAndPermissionsSeeder::class,
|
||||
DevSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
160
database/seeders/DevSeeder.php
Normal file
160
database/seeders/DevSeeder.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\User;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Zona;
|
||||
use App\Models\Tipologia;
|
||||
use App\Models\Territorio;
|
||||
use App\Models\Proclamatore;
|
||||
use App\Models\AnnoTeocratico;
|
||||
use App\Models\Assegnazione;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class DevSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// ─── Admin User ─────────────────────────────
|
||||
$admin = User::firstOrCreate(
|
||||
['email' => 'admin@termanager2.local'],
|
||||
[
|
||||
'name' => 'Amministratore',
|
||||
'password' => bcrypt('password'),
|
||||
]
|
||||
);
|
||||
$admin->assignRole('amministratore');
|
||||
|
||||
$assistente = User::firstOrCreate(
|
||||
['email' => 'assistente@termanager2.local'],
|
||||
[
|
||||
'name' => 'Assistente',
|
||||
'password' => bcrypt('password'),
|
||||
]
|
||||
);
|
||||
$assistente->assignRole('assistente');
|
||||
|
||||
$operatore = User::firstOrCreate(
|
||||
['email' => 'operatore@termanager2.local'],
|
||||
[
|
||||
'name' => 'Operatore',
|
||||
'password' => bcrypt('password'),
|
||||
]
|
||||
);
|
||||
$operatore->assignRole('operatore');
|
||||
|
||||
// ─── Settings ───────────────────────────────
|
||||
Setting::firstOrCreate([], [
|
||||
'congregazione_nome' => 'Congregazione Demo',
|
||||
'giorni_giacenza_da_assegnare' => 120,
|
||||
'giorni_giacenza_prioritari' => 180,
|
||||
'giorni_per_smarrito' => 120,
|
||||
'home_limit_list' => 10,
|
||||
'audit_retention_days' => 730,
|
||||
'setup_completed' => true,
|
||||
]);
|
||||
|
||||
// ─── Zone ───────────────────────────────────
|
||||
$zone = [];
|
||||
foreach (['Centro', 'Nord', 'Sud', 'Est', 'Ovest'] as $nome) {
|
||||
$zone[$nome] = Zona::firstOrCreate(['nome' => $nome]);
|
||||
}
|
||||
|
||||
// ─── Tipologie ─────────────────────────────
|
||||
$tipologie = [];
|
||||
foreach (['Residenziale', 'Commerciale', 'Rurale', 'Telefono'] as $nome) {
|
||||
$tipologie[$nome] = Tipologia::firstOrCreate(['nome' => $nome]);
|
||||
}
|
||||
|
||||
// ─── Proclamatori ───────────────────────────
|
||||
$nomi = [
|
||||
['Mario', 'Rossi'], ['Luisa', 'Bianchi'], ['Giovanni', 'Verdi'],
|
||||
['Anna', 'Neri'], ['Paolo', 'Esposito'], ['Francesca', 'Romano'],
|
||||
['Marco', 'Colombo'], ['Sara', 'Ricci'], ['Luca', 'Marino'],
|
||||
['Elena', 'Greco'], ['Roberto', 'Bruno'], ['Chiara', 'Gallo'],
|
||||
];
|
||||
|
||||
$proclamatori = [];
|
||||
foreach ($nomi as [$nome, $cognome]) {
|
||||
$proclamatori[] = Proclamatore::firstOrCreate(
|
||||
// Can't search encrypted fields, use a simple check
|
||||
['id' => count($proclamatori) + 1],
|
||||
['nome' => $nome, 'cognome' => $cognome, 'attivo' => true]
|
||||
);
|
||||
}
|
||||
// Re-fetch to get proper IDs
|
||||
$proclamatori = Proclamatore::all();
|
||||
|
||||
// ─── Territori ──────────────────────────────
|
||||
$zoneKeys = array_values($zone);
|
||||
$tipoKeys = array_values($tipologie);
|
||||
|
||||
for ($i = 1; $i <= 30; $i++) {
|
||||
Territorio::firstOrCreate(
|
||||
['numero' => (string) $i],
|
||||
[
|
||||
'zona_id' => $zoneKeys[($i - 1) % count($zoneKeys)]->id,
|
||||
'tipologia_id' => $tipoKeys[($i - 1) % count($tipoKeys)]->id,
|
||||
'note' => $i <= 5 ? "Note territorio $i" : null,
|
||||
'confini' => "Confini del territorio $i",
|
||||
'attivo' => $i <= 28, // 2 territories inactive
|
||||
'prioritario' => $i <= 3, // 3 manual priority
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Anno teocratico ────────────────────────
|
||||
$anno = AnnoTeocratico::corrente();
|
||||
|
||||
// ─── Assegnazioni di esempio ────────────────
|
||||
$territori = Territorio::where('attivo', true)->get();
|
||||
|
||||
// 10 closed assignments (various dates)
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$territorio = $territori[$i];
|
||||
$proclamatore = $proclamatori[$i % $proclamatori->count()];
|
||||
$assignedAt = Carbon::now()->subDays(rand(30, 200));
|
||||
$returnedAt = $assignedAt->copy()->addDays(rand(14, 90));
|
||||
|
||||
if ($returnedAt->isFuture()) {
|
||||
$returnedAt = now()->subDays(rand(1, 10));
|
||||
}
|
||||
|
||||
Assegnazione::firstOrCreate(
|
||||
[
|
||||
'territorio_id' => $territorio->id,
|
||||
'anno_teocratico_id' => $anno->id,
|
||||
'assigned_at' => $assignedAt->toDateString(),
|
||||
],
|
||||
[
|
||||
'proclamatore_id' => $proclamatore->id,
|
||||
'returned_at' => $returnedAt->toDateString(),
|
||||
'created_by' => $admin->id,
|
||||
'returned_by' => $admin->id,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// 5 open assignments (currently assigned)
|
||||
for ($i = 15; $i < 20; $i++) {
|
||||
$territorio = $territori[$i];
|
||||
$proclamatore = $proclamatori[$i % $proclamatori->count()];
|
||||
$assignedAt = Carbon::now()->subDays(rand(5, 150));
|
||||
|
||||
Assegnazione::firstOrCreate(
|
||||
[
|
||||
'territorio_id' => $territorio->id,
|
||||
'anno_teocratico_id' => $anno->id,
|
||||
'assigned_at' => $assignedAt->toDateString(),
|
||||
],
|
||||
[
|
||||
'proclamatore_id' => $proclamatore->id,
|
||||
'returned_at' => null,
|
||||
'created_by' => $admin->id,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
55
database/seeders/RolesAndPermissionsSeeder.php
Normal file
55
database/seeders/RolesAndPermissionsSeeder.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class RolesAndPermissionsSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// Reset cached roles and permissions
|
||||
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
|
||||
|
||||
// Create permissions
|
||||
$permissions = [
|
||||
'settings.manage',
|
||||
'proclamatori.manage',
|
||||
'territori.manage',
|
||||
'campagne.manage',
|
||||
'registro.view',
|
||||
'registro.export',
|
||||
'territori.assign',
|
||||
'territori.return',
|
||||
'audit.view',
|
||||
'audit.export',
|
||||
];
|
||||
|
||||
foreach ($permissions as $permission) {
|
||||
Permission::firstOrCreate(['name' => $permission]);
|
||||
}
|
||||
|
||||
// Amministratore: all permissions
|
||||
$admin = Role::firstOrCreate(['name' => 'amministratore']);
|
||||
$admin->syncPermissions($permissions);
|
||||
|
||||
// Assistente: proclamatori, campagne, assign, return
|
||||
$assistente = Role::firstOrCreate(['name' => 'assistente']);
|
||||
$assistente->syncPermissions([
|
||||
'proclamatori.manage',
|
||||
'campagne.manage',
|
||||
'territori.assign',
|
||||
'territori.return',
|
||||
'registro.view',
|
||||
]);
|
||||
|
||||
// Operatore: assign and return only
|
||||
$operatore = Role::firstOrCreate(['name' => 'operatore']);
|
||||
$operatore->syncPermissions([
|
||||
'territori.assign',
|
||||
'territori.return',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user