diff --git a/Migrations/2026_03_24_000000_add_feature_code_foreign_keys.php b/Migrations/2026_03_24_000000_add_feature_code_foreign_keys.php new file mode 100644 index 0000000..9680b1b --- /dev/null +++ b/Migrations/2026_03_24_000000_add_feature_code_foreign_keys.php @@ -0,0 +1,57 @@ +foreign('feature_code', 'usage_alert_feature_code_fk') + ->references('code') + ->on('entitlement_features') + ->cascadeOnUpdate() + ->restrictOnDelete(); + }); + + Schema::table('entitlement_boosts', function (Blueprint $table) { + $table->foreign('feature_code', 'boosts_feature_code_fk') + ->references('code') + ->on('entitlement_features') + ->cascadeOnUpdate() + ->restrictOnDelete(); + }); + + Schema::table('entitlement_usage_records', function (Blueprint $table) { + $table->foreign('feature_code', 'usage_records_feature_code_fk') + ->references('code') + ->on('entitlement_features') + ->cascadeOnUpdate() + ->restrictOnDelete(); + }); + } + + public function down(): void + { + Schema::table('entitlement_usage_alert_history', function (Blueprint $table) { + $table->dropForeign('usage_alert_feature_code_fk'); + }); + + Schema::table('entitlement_boosts', function (Blueprint $table) { + $table->dropForeign('boosts_feature_code_fk'); + }); + + Schema::table('entitlement_usage_records', function (Blueprint $table) { + $table->dropForeign('usage_records_feature_code_fk'); + }); + } +}; diff --git a/Migrations/2026_03_24_000000_cascade_delete_namespaces_on_workspace_delete.php b/Migrations/2026_03_24_000000_cascade_delete_namespaces_on_workspace_delete.php new file mode 100644 index 0000000..bb5f6a5 --- /dev/null +++ b/Migrations/2026_03_24_000000_cascade_delete_namespaces_on_workspace_delete.php @@ -0,0 +1,40 @@ +dropForeign(['workspace_id']); + + $table->foreign('workspace_id') + ->references('id') + ->on('workspaces') + ->cascadeOnDelete(); + }); + } + + public function down(): void + { + Schema::table('namespaces', function (Blueprint $table) { + $table->dropForeign(['workspace_id']); + + $table->foreign('workspace_id') + ->references('id') + ->on('workspaces') + ->nullOnDelete(); + }); + } +}; diff --git a/Migrations/2026_03_24_000000_fix_parent_feature_cascade_delete.php b/Migrations/2026_03_24_000000_fix_parent_feature_cascade_delete.php new file mode 100644 index 0000000..81698fa --- /dev/null +++ b/Migrations/2026_03_24_000000_fix_parent_feature_cascade_delete.php @@ -0,0 +1,47 @@ +dropForeign(['parent_feature_id']); + + $table->foreign('parent_feature_id') + ->references('id') + ->on('entitlement_features') + ->cascadeOnDelete(); + }); + } + + /** + * Revert to the original nullOnDelete behaviour. + */ + public function down(): void + { + Schema::table('entitlement_features', function (Blueprint $table) { + $table->dropForeign(['parent_feature_id']); + + $table->foreign('parent_feature_id') + ->references('id') + ->on('entitlement_features') + ->nullOnDelete(); + }); + } +};