sistemazione migrate

This commit is contained in:
Mariano
2026-06-17 19:13:40 +02:00
parent 7302146a77
commit 005fa5b4a3
33 changed files with 635 additions and 498 deletions
+43
View File
@@ -380,3 +380,46 @@ if (!empty($contatto['individuo_id'])) { create }
**Fix**: **Fix**:
1. `VistaReportController@update` (linea 101-103): aggiunto `if ($request->expectsJson()) { return response()->json([...]); }` — così il fetch riceve JSON 200, non un redirect 302. 1. `VistaReportController@update` (linea 101-103): aggiunto `if ($request->expectsJson()) { return response()->json([...]); }` — così il fetch riceve JSON 200, non un redirect 302.
2. Fetch headers in `table-settings.blade.php`: aggiunto `'Accept': 'application/json'` — necessario perché `expectsJson()` controlla l'header `Accept`, non `Content-Type`. 2. Fetch headers in `table-settings.blade.php`: aggiunto `'Accept': 'application/json'` — necessario perché `expectsJson()` controlla l'header `Accept`, non `Content-Type`.
## 2026-06-10 — Fix: tutte le migration idempotenti + seeders idempotenti
**Problema**: `php artisan migrate` falliva su tabelle già esistenti. `php artisan db:seed` creava duplicati su re-run.
### Migration: hasTable guard su tutti i 27 file mancanti
Aggiunto `if (!Schema::hasTable('table_name')) { ... }` wrapper a tutte le 27 migration file (44 `Schema::create()` calls) che ne erano prive, usando script Node.js di trasformazione automatica:
- `2024_01_01_000002_create_comuni_diocesi_tables.php`
- `2024_01_01_000003_create_individui_table.php`
- `2024_01_01_000004_create_contatti_table.php`
- `2024_01_01_000005_create_gruppi_table.php`
- `2024_01_01_000006_create_gruppo_individuo_table.php`
- `2024_01_01_000007_create_eventi_table.php`
- `2024_01_01_000008_create_documenti_table.php`
- `2024_01_01_000009_create_mailing_tables.php`
- `2024_01_01_000010_create_notifiche_table.php`
- `2024_01_01_000011_create_users_table.php`
- `2024_01_01_000012_create_cache_and_jobs_tables.php`
- `2024_01_01_000019_create_eventi_documenti_table.php`
- `2024_01_01_000022_create_table_viste_report.php`
- `2026_05_10_000001_create_tipologie_documenti_table.php`
- `2026_05_10_000002_add_acl_tables.php`
- `2026_05_10_125210_create_permission_tables.php` (usa `$tableNames[...]` dinamici)
- `2026_05_11_000001_create_email_settings_table.php`
- `2026_05_11_000002_create_email_folders_table.php`
- `2026_05_11_000003_create_email_messages_table.php`
- `2026_05_11_000007_create_email_attachments_table.php`
- `2026_05_12_000001_create_ruoli_table.php`
- `2026_05_25_000001_create_report_custom_table.php`
- `2026_05_26_000001_create_tipologie_eventi_table.php`
- `2026_05_26_000002_create_sender_accounts_table.php`
- `2026_05_27_000001_create_documenti_cartelle_table.php`
- `2026_05_27_113245_create_storage_repositories_table.php`
- `2026_06_02_000001_create_calendario_connessioni_table.php`
### Seeder: firstOrCreate per idempotenza
- `DiocesiSeeder.php`: `Diocesi::create()``Diocesi::firstOrCreate(['nome' => $d['nome']], $d)`
- `ComuniSeeder.php`: `Comune::create()``Comune::firstOrCreate(['codice_istat' => $c['codice_istat']], $c)`
- `DatabaseSeeder.php`: `User::create()``User::firstOrCreate(['email' => 'admin@glastree.local'], [...])`, con guardia su `role_preset_id`
**Risultato**: `php artisan migrate --seed` è ora completamente idempotente. Zero errori su 62 migration + 6 seeder.
@@ -8,6 +8,10 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (Schema::hasTable('tenants')) {
return;
}
Schema::create('tenants', function (Blueprint $table) { Schema::create('tenants', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('nome'); $table->string('nome');
@@ -8,13 +8,16 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('diocesi')) {
Schema::create('diocesi', function (Blueprint $table) { Schema::create('diocesi', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('nome'); $table->string('nome');
$table->string('regione')->nullable(); $table->string('regione')->nullable();
$table->timestamps(); $table->timestamps();
}); });
}
if (!Schema::hasTable('comuni')) {
Schema::create('comuni', function (Blueprint $table) { Schema::create('comuni', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('nome'); $table->string('nome');
@@ -29,6 +32,7 @@ return new class extends Migration
$table->index('sigla_provincia'); $table->index('sigla_provincia');
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('individui')) {
Schema::create('individui', function (Blueprint $table) { Schema::create('individui', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null'); $table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null');
@@ -30,6 +31,7 @@ return new class extends Migration
$table->index('cognome'); $table->index('cognome');
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('contatti')) {
Schema::create('contatti', function (Blueprint $table) { Schema::create('contatti', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('individuo_id')->constrained('individui')->onDelete('cascade'); $table->foreignId('individuo_id')->constrained('individui')->onDelete('cascade');
@@ -19,6 +20,7 @@ return new class extends Migration
$table->index('individuo_id'); $table->index('individuo_id');
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('gruppi')) {
Schema::create('gruppi', function (Blueprint $table) { Schema::create('gruppi', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null'); $table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null');
@@ -27,6 +28,7 @@ return new class extends Migration
$table->index('parent_id'); $table->index('parent_id');
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('gruppo_individuo')) {
Schema::create('gruppo_individuo', function (Blueprint $table) { Schema::create('gruppo_individuo', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('gruppo_id')->constrained('gruppi')->onDelete('cascade'); $table->foreignId('gruppo_id')->constrained('gruppi')->onDelete('cascade');
@@ -18,6 +19,7 @@ return new class extends Migration
$table->unique(['gruppo_id', 'individuo_id']); $table->unique(['gruppo_id', 'individuo_id']);
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('eventi')) {
Schema::create('eventi', function (Blueprint $table) { Schema::create('eventi', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null'); $table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null');
@@ -23,14 +24,18 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
$table->index('tenant_id'); $table->index('tenant_id');
}); });
}
if (!Schema::hasTable('eventi_gruppi')) {
Schema::create('eventi_gruppi', function (Blueprint $table) { Schema::create('eventi_gruppi', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('evento_id')->constrained('eventi')->onDelete('cascade'); $table->foreignId('evento_id')->constrained('eventi')->onDelete('cascade');
$table->foreignId('gruppo_id')->constrained('gruppi')->onDelete('cascade'); $table->foreignId('gruppo_id')->constrained('gruppi')->onDelete('cascade');
$table->timestamps(); $table->timestamps();
}); });
}
if (!Schema::hasTable('eventi_responsabili')) {
Schema::create('eventi_responsabili', function (Blueprint $table) { Schema::create('eventi_responsabili', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('evento_id')->constrained('eventi')->onDelete('cascade'); $table->foreignId('evento_id')->constrained('eventi')->onDelete('cascade');
@@ -38,6 +43,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('documenti')) {
Schema::create('documenti', function (Blueprint $table) { Schema::create('documenti', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null'); $table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null');
@@ -25,6 +26,7 @@ return new class extends Migration
$table->index('tenant_id'); $table->index('tenant_id');
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('mailing_lists')) {
Schema::create('mailing_lists', function (Blueprint $table) { Schema::create('mailing_lists', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null'); $table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null');
@@ -17,7 +18,9 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
$table->index('tenant_id'); $table->index('tenant_id');
}); });
}
if (!Schema::hasTable('mailing_contacts')) {
Schema::create('mailing_contacts', function (Blueprint $table) { Schema::create('mailing_contacts', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('mailing_list_id')->constrained('mailing_lists')->onDelete('cascade'); $table->foreignId('mailing_list_id')->constrained('mailing_lists')->onDelete('cascade');
@@ -28,7 +31,9 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
$table->unique(['mailing_list_id', 'individuo_id']); $table->unique(['mailing_list_id', 'individuo_id']);
}); });
}
if (!Schema::hasTable('mailing_messaggi')) {
Schema::create('mailing_messaggi', function (Blueprint $table) { Schema::create('mailing_messaggi', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null'); $table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null');
@@ -46,6 +51,7 @@ return new class extends Migration
$table->index('tenant_id'); $table->index('tenant_id');
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('notifiche')) {
Schema::create('notifiche', function (Blueprint $table) { Schema::create('notifiche', function (Blueprint $table) {
$table->id(); $table->id();
$table->unsignedBigInteger('user_id')->nullable(); $table->unsignedBigInteger('user_id')->nullable();
@@ -21,6 +22,7 @@ return new class extends Migration
$table->index('user_id'); $table->index('user_id');
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('users')) {
Schema::create('users', function (Blueprint $table) { Schema::create('users', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null'); $table->foreignId('tenant_id')->nullable()->constrained('tenants')->onDelete('set null');
@@ -21,13 +22,17 @@ return new class extends Migration
$table->index('tenant_id'); $table->index('tenant_id');
$table->index('email'); $table->index('email');
}); });
}
if (!Schema::hasTable('password_reset_tokens')) {
Schema::create('password_reset_tokens', function (Blueprint $table) { Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary(); $table->string('email')->primary();
$table->string('token'); $table->string('token');
$table->timestamp('created_at')->nullable(); $table->timestamp('created_at')->nullable();
}); });
}
if (!Schema::hasTable('sessions')) {
Schema::create('sessions', function (Blueprint $table) { Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary(); $table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index(); $table->foreignId('user_id')->nullable()->index();
@@ -37,6 +42,7 @@ return new class extends Migration
$table->integer('last_activity')->index(); $table->integer('last_activity')->index();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,18 +8,23 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('cache')) {
Schema::create('cache', function (Blueprint $table) { Schema::create('cache', function (Blueprint $table) {
$table->string('key')->primary(); $table->string('key')->primary();
$table->mediumText('value'); $table->mediumText('value');
$table->integer('expiration'); $table->integer('expiration');
}); });
}
if (!Schema::hasTable('cache_locks')) {
Schema::create('cache_locks', function (Blueprint $table) { Schema::create('cache_locks', function (Blueprint $table) {
$table->string('key')->primary(); $table->string('key')->primary();
$table->string('owner'); $table->string('owner');
$table->integer('expiration'); $table->integer('expiration');
}); });
}
if (!Schema::hasTable('jobs')) {
Schema::create('jobs', function (Blueprint $table) { Schema::create('jobs', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('queue')->index(); $table->string('queue')->index();
@@ -29,7 +34,9 @@ return new class extends Migration
$table->unsignedInteger('available_at'); $table->unsignedInteger('available_at');
$table->unsignedInteger('created_at'); $table->unsignedInteger('created_at');
}); });
}
if (!Schema::hasTable('job_batches')) {
Schema::create('job_batches', function (Blueprint $table) { Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary(); $table->string('id')->primary();
$table->string('name'); $table->string('name');
@@ -42,7 +49,9 @@ return new class extends Migration
$table->integer('created_at'); $table->integer('created_at');
$table->integer('finished_at')->nullable(); $table->integer('finished_at')->nullable();
}); });
}
if (!Schema::hasTable('failed_jobs')) {
Schema::create('failed_jobs', function (Blueprint $table) { Schema::create('failed_jobs', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('uuid')->unique(); $table->string('uuid')->unique();
@@ -53,6 +62,7 @@ return new class extends Migration
$table->timestamp('failed_at'); $table->timestamp('failed_at');
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('eventi_documenti')) {
Schema::create('eventi_documenti', function (Blueprint $table) { Schema::create('eventi_documenti', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('evento_id')->constrained('eventi')->onDelete('cascade'); $table->foreignId('evento_id')->constrained('eventi')->onDelete('cascade');
@@ -15,6 +16,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('viste_report')) {
Schema::create('viste_report', function (Blueprint $table) { Schema::create('viste_report', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('user_id')->constrained('users')->onDelete('cascade'); $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
@@ -22,6 +23,7 @@ return new class extends Migration
$table->index('user_id'); $table->index('user_id');
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('tipologie_documenti')) {
Schema::create('tipologie_documenti', function (Blueprint $table) { Schema::create('tipologie_documenti', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('nome', 50)->unique(); $table->string('nome', 50)->unique();
@@ -16,6 +17,7 @@ return new class extends Migration
$table->boolean('attiva')->default(true); $table->boolean('attiva')->default(true);
$table->timestamps(); $table->timestamps();
}); });
}
$defaultTipologie = ['avatar', 'galleria', 'documento', 'statuto', 'altro']; $defaultTipologie = ['avatar', 'galleria', 'documento', 'statuto', 'altro'];
foreach ($defaultTipologie as $i => $nome) { foreach ($defaultTipologie as $i => $nome) {
@@ -14,6 +14,7 @@ return new class extends Migration
}); });
} }
if (!Schema::hasTable('activity_logs')) {
Schema::create('activity_logs', function (Blueprint $table) { Schema::create('activity_logs', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade'); $table->foreignId('user_id')->constrained()->onDelete('cascade');
@@ -28,7 +29,9 @@ return new class extends Migration
$table->index(['created_at']); $table->index(['created_at']);
$table->index(['action']); $table->index(['action']);
}); });
}
if (!Schema::hasTable('role_presets')) {
Schema::create('role_presets', function (Blueprint $table) { Schema::create('role_presets', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name', 50)->unique(); $table->string('name', 50)->unique();
@@ -37,6 +40,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -23,6 +23,7 @@ return new class extends Migration
/** /**
* See `docs/prerequisites.md` for suggested lengths on 'name' and 'guard_name' if "1071 Specified key was too long" errors are encountered. * See `docs/prerequisites.md` for suggested lengths on 'name' and 'guard_name' if "1071 Specified key was too long" errors are encountered.
*/ */
if (!Schema::hasTable($tableNames['permissions'])) {
Schema::create($tableNames['permissions'], static function (Blueprint $table) { Schema::create($tableNames['permissions'], static function (Blueprint $table) {
$table->id(); // permission id $table->id(); // permission id
$table->string('name'); $table->string('name');
@@ -31,10 +32,12 @@ return new class extends Migration
$table->unique(['name', 'guard_name']); $table->unique(['name', 'guard_name']);
}); });
}
/** /**
* See `docs/prerequisites.md` for suggested lengths on 'name' and 'guard_name' if "1071 Specified key was too long" errors are encountered. * See `docs/prerequisites.md` for suggested lengths on 'name' and 'guard_name' if "1071 Specified key was too long" errors are encountered.
*/ */
if (!Schema::hasTable($tableNames['roles'])) {
Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) { Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) {
$table->id(); // role id $table->id(); // role id
if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing
@@ -50,7 +53,9 @@ return new class extends Migration
$table->unique(['name', 'guard_name']); $table->unique(['name', 'guard_name']);
} }
}); });
}
if (!Schema::hasTable($tableNames['model_has_permissions'])) {
Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) { Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) {
$table->unsignedBigInteger($pivotPermission); $table->unsignedBigInteger($pivotPermission);
@@ -73,7 +78,9 @@ return new class extends Migration
'model_has_permissions_permission_model_type_primary'); 'model_has_permissions_permission_model_type_primary');
} }
}); });
}
if (!Schema::hasTable($tableNames['model_has_roles'])) {
Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) { Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) {
$table->unsignedBigInteger($pivotRole); $table->unsignedBigInteger($pivotRole);
@@ -96,7 +103,9 @@ return new class extends Migration
'model_has_roles_role_model_type_primary'); 'model_has_roles_role_model_type_primary');
} }
}); });
}
if (!Schema::hasTable($tableNames['role_has_permissions'])) {
Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) { Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) {
$table->unsignedBigInteger($pivotPermission); $table->unsignedBigInteger($pivotPermission);
$table->unsignedBigInteger($pivotRole); $table->unsignedBigInteger($pivotRole);
@@ -113,6 +122,7 @@ return new class extends Migration
$table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary'); $table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary');
}); });
}
app('cache') app('cache')
->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('email_settings')) {
Schema::create('email_settings', function (Blueprint $table) { Schema::create('email_settings', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('imap_host')->nullable(); $table->string('imap_host')->nullable();
@@ -29,6 +30,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('email_folders')) {
Schema::create('email_folders', function (Blueprint $table) { Schema::create('email_folders', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name'); $table->string('name');
@@ -20,6 +21,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('email_messages')) {
Schema::create('email_messages', function (Blueprint $table) { Schema::create('email_messages', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('email_folder_id')->constrained('email_folders')->onDelete('cascade'); $table->foreignId('email_folder_id')->constrained('email_folders')->onDelete('cascade');
@@ -38,6 +39,7 @@ return new class extends Migration
$table->index('received_at'); $table->index('received_at');
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('email_attachments')) {
Schema::create('email_attachments', function (Blueprint $table) { Schema::create('email_attachments', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('email_message_id')->constrained('email_messages')->onDelete('cascade'); $table->foreignId('email_message_id')->constrained('email_messages')->onDelete('cascade');
@@ -20,6 +21,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('ruoli')) {
Schema::create('ruoli', function (Blueprint $table) { Schema::create('ruoli', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('nome', 50)->unique(); $table->string('nome', 50)->unique();
@@ -16,6 +17,7 @@ return new class extends Migration
$table->boolean('attiva')->default(true); $table->boolean('attiva')->default(true);
$table->timestamps(); $table->timestamps();
}); });
}
$defaultRuoli = [ $defaultRuoli = [
['nome' => 'Membro', 'descrizione' => 'Membro del gruppo'], ['nome' => 'Membro', 'descrizione' => 'Membro del gruppo'],
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('report_custom')) {
Schema::create('report_custom', function (Blueprint $table) { Schema::create('report_custom', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('user_id')->constrained('users')->onDelete('cascade'); $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
@@ -18,6 +19,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -10,6 +10,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('tipologie_eventi')) {
Schema::create('tipologie_eventi', function (Blueprint $table) { Schema::create('tipologie_eventi', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('nome', 50)->unique(); $table->string('nome', 50)->unique();
@@ -18,6 +19,7 @@ return new class extends Migration
$table->boolean('attiva')->default(true); $table->boolean('attiva')->default(true);
$table->timestamps(); $table->timestamps();
}); });
}
DB::table('tipologie_eventi')->insert([ DB::table('tipologie_eventi')->insert([
['nome' => 'catechesi', 'descrizione' => 'Catechesi', 'ordine' => 0, 'attiva' => true], ['nome' => 'catechesi', 'descrizione' => 'Catechesi', 'ordine' => 0, 'attiva' => true],
@@ -10,6 +10,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('sender_accounts')) {
Schema::create('sender_accounts', function (Blueprint $table) { Schema::create('sender_accounts', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('email_address')->unique(); $table->string('email_address')->unique();
@@ -26,6 +27,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('documenti_cartelle')) {
Schema::create('documenti_cartelle', function (Blueprint $table) { Schema::create('documenti_cartelle', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('parent_id')->nullable()->constrained('documenti_cartelle')->onDelete('cascade'); $table->foreignId('parent_id')->nullable()->constrained('documenti_cartelle')->onDelete('cascade');
@@ -15,6 +16,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -8,6 +8,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('storage_repositories')) {
Schema::create('storage_repositories', function (Blueprint $table) { Schema::create('storage_repositories', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('nome'); $table->string('nome');
@@ -18,6 +19,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
@@ -10,6 +10,7 @@ return new class extends Migration
{ {
public function up(): void public function up(): void
{ {
if (!Schema::hasTable('calendario_connessioni')) {
Schema::create('calendario_connessioni', function (Blueprint $table) { Schema::create('calendario_connessioni', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('nome'); $table->string('nome');
@@ -26,6 +27,7 @@ return new class extends Migration
$table->timestamps(); $table->timestamps();
}); });
} }
}
public function down(): void public function down(): void
{ {
+1 -1
View File
@@ -68,7 +68,7 @@ class ComuniSeeder extends Seeder
]; ];
foreach ($comuni as $c) { foreach ($comuni as $c) {
Comune::create($c); Comune::firstOrCreate(['codice_istat' => $c['codice_istat']], $c);
} }
} }
} }
+7 -3
View File
@@ -20,9 +20,10 @@ class DatabaseSeeder extends Seeder
DockerBaseDataSeeder::class, DockerBaseDataSeeder::class,
]); ]);
$admin = User::create([ $admin = User::firstOrCreate(
['email' => 'admin@glastree.local'],
[
'name' => 'Admin', 'name' => 'Admin',
'email' => 'admin@glastree.local',
'password' => bcrypt('password'), 'password' => bcrypt('password'),
'is_admin' => true, 'is_admin' => true,
'status' => 'active', 'status' => 'active',
@@ -34,9 +35,12 @@ class DatabaseSeeder extends Seeder
'mailing' => 2, 'mailing' => 2,
'viste' => 2, 'viste' => 2,
], ],
]); ]
);
if (!$admin->role_preset_id) {
$admin->role_preset_id = 1; $admin->role_preset_id = 1;
$admin->save(); $admin->save();
} }
}
} }
+1 -1
View File
@@ -149,7 +149,7 @@ class DiocesiSeeder extends Seeder
]; ];
foreach ($diocesi as $d) { foreach ($diocesi as $d) {
Diocesi::create($d); Diocesi::firstOrCreate(['nome' => $d['nome']], $d);
} }
} }
} }