diff --git a/database/migrations/2024_04_15_000000_add_parent_id_to_taxonomy_terms.php b/database/migrations/2024_04_15_000000_add_parent_id_to_taxonomy_terms.php deleted file mode 100644 index 19719e63..00000000 --- a/database/migrations/2024_04_15_000000_add_parent_id_to_taxonomy_terms.php +++ /dev/null @@ -1,30 +0,0 @@ -foreignId('parent_id')->nullable()->constrained('taxonomy_terms'); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('taxonomy_terms', function (Blueprint $table) { - if (DB::connection()->getDriverName() !== 'sqlite') { - $table->dropForeign('taxonomy_terms_parent_id_foreign'); - } - }); - } -}; diff --git a/database/migrations/2024_04_16_000000_add_soft_deletes_to_tables.php b/database/migrations/2024_04_16_000000_add_soft_deletes_to_tables.php deleted file mode 100644 index c31bcad7..00000000 --- a/database/migrations/2024_04_16_000000_add_soft_deletes_to_tables.php +++ /dev/null @@ -1,39 +0,0 @@ -softDeletes(); - }); - Schema::table('taxonomies', function (Blueprint $table) { - $table->softDeletes(); - }); - Schema::table('taxonomy_terms', function (Blueprint $table) { - $table->softDeletes(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('authors', function (Blueprint $table) { - $table->dropSoftDeletes(); - }); - Schema::table('taxonomies', function (Blueprint $table) { - $table->dropSoftDeletes(); - }); - Schema::table('taxonomy_terms', function (Blueprint $table) { - $table->dropSoftDeletes(); - }); - } -}; diff --git a/database/migrations/2024_05_14_000000_add_taxonomy_code.php b/database/migrations/2024_05_14_000000_add_taxonomy_code.php deleted file mode 100644 index eff334c8..00000000 --- a/database/migrations/2024_05_14_000000_add_taxonomy_code.php +++ /dev/null @@ -1,36 +0,0 @@ -string('code')->nullable()->after('name'); - }); - - // Populate codes - Taxonomy::all()->each(function ($taxonomy) { - $taxonomy->update([ - 'code' => Str::slug($taxonomy->name), - ]); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('taxonomies', function (Blueprint $table) { - $table->dropColumn('code'); - }); - } -}; diff --git a/database/migrations/2024_05_17_000001_adjust_page_authors.php b/database/migrations/2024_05_17_000001_adjust_page_authors.php deleted file mode 100644 index 83ae5be7..00000000 --- a/database/migrations/2024_05_17_000001_adjust_page_authors.php +++ /dev/null @@ -1,44 +0,0 @@ -get()->each(function (Page $page) { - if ($page->author_id) { - $page->authors()->sync($page->author_id); - } - }); - - - Schema::table('pages', function (Blueprint $table) { - if (DB::connection()->getDriverName() !== 'sqlite') { - $table->dropConstrainedForeignId('author_id'); - } - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('pages', function (Blueprint $table) { - $table->foreignId('author_id')->nullable(); - }); - - Page::withoutGlobalScopes()->get()->each(function (Page $page) { - if ($page->authors()->count() > 0) { - $page->author_id = $page->authors->first()->id; - } - }); - } -}; diff --git a/database/migrations/2024_06_19_000000_adjust_user_sso_links_table.php b/database/migrations/2024_06_19_000000_adjust_user_sso_links_table.php deleted file mode 100644 index 05641fd0..00000000 --- a/database/migrations/2024_06_19_000000_adjust_user_sso_links_table.php +++ /dev/null @@ -1,29 +0,0 @@ -text('provider_token')->change(); - $table->text('provider_refresh_token')->nullable()->change(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::table('user_sso_links', function (Blueprint $table) { - $table->string('provider_token')->change(); - $table->string('provider_refresh_token')->nullable()->change(); - }); - } -}; diff --git a/src/Providers/FilaCmsServiceProvider.php b/src/Providers/FilaCmsServiceProvider.php index 199c7214..7c08e618 100644 --- a/src/Providers/FilaCmsServiceProvider.php +++ b/src/Providers/FilaCmsServiceProvider.php @@ -137,7 +137,6 @@ function (\Lab404\Impersonate\Events\LeaveImpersonation $event) { ], 'fila-cms' ); - $this->loadMigrationsFrom(__DIR__ . '/../../database/migrations'); \Filament\Support\Facades\FilamentIcon::register([ 'filament-password-input::regenerate' => 'heroicon-m-key', @@ -150,6 +149,9 @@ function (\Lab404\Impersonate\Events\LeaveImpersonation $event) { Blade::componentNamespace('Portable\\FilaCms\\Views\\Components', 'fila-cms'); config(['versionable.user_model' => config('auth.providers.users.model')]); config(['scout.driver' => config('fila-cms.search.driver', 'meilisearch')]); + // Temporary, will be reverted in next PR + //config(['permission.teams' => config('fila-cms.multitenancy')]); + //config(['permission.column_names.team_foreign_key' => config('fila-cms.tenant_id_field')]); Event::listen(Login::class, AuthenticationListener::class); Event::listen(Verified::class, UserVerifiedListener::class); @@ -221,11 +223,14 @@ public function register() __DIR__ . '/../../config/fila-cms.php' => config_path('fila-cms.php'), ], 'fila-cms-config'); - $file = (__DIR__.'/../../database/stubs/create_content_roles.php.stub'); - - $this->publishes([ - $file => $this->getMigrationFileName('create_content_roles.php'), - ], 'fila-cms-migrations'); + // Get all the migration stubs and publish them + $filePath = __DIR__.'/../../stubs/database/migrations/auto*.stub'; + $files = glob($filePath); + foreach ($files as $file) { + $this->publishes([ + $file => $this->getMigrationFileName(basename($file, '.stub') . '.php'), + ], 'fila-cms-migrations'); + } // use the vendor configuration file as fallback $this->mergeConfigFrom( diff --git a/stubs/database/migrations/auto_01_create_tenants_table.stub b/stubs/database/migrations/auto_01_create_tenants_table.stub new file mode 100644 index 00000000..a91774e3 --- /dev/null +++ b/stubs/database/migrations/auto_01_create_tenants_table.stub @@ -0,0 +1,36 @@ +id(); + $table->string('name'); + $table->string('domain')->unique()->nullable(); + $table->string('filament_theme')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + if (!config('fila-cms.multitenancy')) { + return; + } + + Schema::dropIfExists('tenants'); + } +}; diff --git a/stubs/database/migrations/auto_02_create_tenant_members_table.stub b/stubs/database/migrations/auto_02_create_tenant_members_table.stub new file mode 100644 index 00000000..e3455e1b --- /dev/null +++ b/stubs/database/migrations/auto_02_create_tenant_members_table.stub @@ -0,0 +1,33 @@ +foreignId('tenant_id')->references('id')->on('tenants')->onDelete('cascade'); + $table->foreignId('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + if (!config('fila-cms.multitenancy')) { + return; + } + + Schema::dropIfExists('tenant_members'); + } +}; diff --git a/database/stubs/create_content_roles.php.stub b/stubs/database/migrations/auto_03_create_content_roles.stub similarity index 69% rename from database/stubs/create_content_roles.php.stub rename to stubs/database/migrations/auto_03_create_content_roles.stub index a3908796..f1c71d0e 100644 --- a/database/stubs/create_content_roles.php.stub +++ b/stubs/database/migrations/auto_03_create_content_roles.stub @@ -12,6 +12,10 @@ return new class () extends Migration { { Schema::create('content_roles', function (Blueprint $table) { $table->id(); + if (config('fila-cms.multitenancy')) { + $table->unsignedBigInteger(config('fila-cms.tenant_id_field'))->nullable(); + $table->foreign(config('fila-cms.tenant_id_field'))->references('id')->on('tenants')->onDelete('cascade'); + } $table->morphs('roleable'); $table->foreignId('role_id')->constrained('roles'); $table->timestamps(); diff --git a/database/migrations/2024_02_08_000000_create_taxonomies_table.php b/stubs/database/migrations/auto_04_create_taxonomies_table.stub similarity index 61% rename from database/migrations/2024_02_08_000000_create_taxonomies_table.php rename to stubs/database/migrations/auto_04_create_taxonomies_table.stub index 447adb45..5180af6e 100644 --- a/database/migrations/2024_02_08_000000_create_taxonomies_table.php +++ b/stubs/database/migrations/auto_04_create_taxonomies_table.stub @@ -13,6 +13,12 @@ public function up(): void Schema::create('taxonomies', function (Blueprint $table) { $table->id(); $table->string('name'); + $table->string('code')->nullable()->after('name'); + if (config('fila-cms.multitenancy')) { + $table->unsignedBigInteger(config('fila-cms.tenant_id_field'))->nullable(); + $table->foreign(config('fila-cms.tenant_id_field'))->references('id')->on('tenants')->onDelete('cascade'); + } + $table->softDeletes(); $table->timestamps(); $table->index('name'); diff --git a/database/migrations/2024_02_08_100000_create_taxonomy_terms_table.php b/stubs/database/migrations/auto_05_create_taxonomy_terms_table.stub similarity index 84% rename from database/migrations/2024_02_08_100000_create_taxonomy_terms_table.php rename to stubs/database/migrations/auto_05_create_taxonomy_terms_table.stub index dfefb2bf..f8180d4d 100644 --- a/database/migrations/2024_02_08_100000_create_taxonomy_terms_table.php +++ b/stubs/database/migrations/auto_05_create_taxonomy_terms_table.stub @@ -12,8 +12,10 @@ public function up(): void { Schema::create('taxonomy_terms', function (Blueprint $table) { $table->id(); + $table->foreignId('parent_id')->nullable()->constrained('taxonomy_terms'); $table->string('name'); $table->foreignId('taxonomy_id')->constrained(); + $table->softDeletes(); $table->timestamps(); $table->index('name'); }); diff --git a/database/migrations/2024_02_09_300000_create_authors_table.php b/stubs/database/migrations/auto_06_create_authors_table.stub similarity index 72% rename from database/migrations/2024_02_09_300000_create_authors_table.php rename to stubs/database/migrations/auto_06_create_authors_table.stub index 3f58bd08..65d03540 100644 --- a/database/migrations/2024_02_09_300000_create_authors_table.php +++ b/stubs/database/migrations/auto_06_create_authors_table.stub @@ -12,13 +12,19 @@ public function up(): void { Schema::create('authors', function (Blueprint $table) { $table->id(); + if (config('fila-cms.multitenancy')) { + $table->unsignedBigInteger(config('fila-cms.tenant_id_field'))->nullable(); + $table->foreign(config('fila-cms.tenant_id_field'))->references('id')->on('tenants')->onDelete('cascade'); + } $table->string('first_name'); $table->string('last_name')->nullable(); $table->boolean('is_individual')->default(true); + $table->softDeletes(); $table->timestamps(); $table->index('first_name'); $table->index('last_name'); $table->index('is_individual'); + }); } diff --git a/database/migrations/2024_02_09_400000_create_pages_table.php b/stubs/database/migrations/auto_07_create_pages_table.stub similarity index 80% rename from database/migrations/2024_02_09_400000_create_pages_table.php rename to stubs/database/migrations/auto_07_create_pages_table.stub index 3e206f20..ce3e6099 100644 --- a/database/migrations/2024_02_09_400000_create_pages_table.php +++ b/stubs/database/migrations/auto_07_create_pages_table.stub @@ -12,6 +12,10 @@ public function up(): void { Schema::create('pages', function (Blueprint $table) { $table->id(); + if (config('fila-cms.multitenancy')) { + $table->unsignedBigInteger(config('fila-cms.tenant_id_field'))->nullable(); + $table->foreign(config('fila-cms.tenant_id_field'))->references('id')->on('tenants')->onDelete('cascade'); + } $table->string('title'); $table->string('slug'); $table->boolean('is_draft')->default(true); @@ -21,7 +25,6 @@ public function up(): void $table->foreignId('created_user_id')->constrained('users'); $table->foreignId('updated_user_id')->constrained('users'); - $table->foreignId('author_id')->nullable()->constrained('authors'); $table->index('title'); $table->index('slug'); diff --git a/database/migrations/2024_02_23_000000_create_taxonomy_resources.php b/stubs/database/migrations/auto_08_create_taxonomy_resources.stub similarity index 100% rename from database/migrations/2024_02_23_000000_create_taxonomy_resources.php rename to stubs/database/migrations/auto_08_create_taxonomy_resources.stub diff --git a/database/migrations/2024_02_23_222545_create_taxonomyables.php b/stubs/database/migrations/auto_09_create_taxonomyables.stub similarity index 100% rename from database/migrations/2024_02_23_222545_create_taxonomyables.php rename to stubs/database/migrations/auto_09_create_taxonomyables.stub diff --git a/database/migrations/2024_03_20_000000_modify_contents_data_type.php b/stubs/database/migrations/auto_10_modify_contents_data_type.stub similarity index 100% rename from database/migrations/2024_03_20_000000_modify_contents_data_type.php rename to stubs/database/migrations/auto_10_modify_contents_data_type.stub diff --git a/database/migrations/2024_04_11_000000_create_media_library_table.php b/stubs/database/migrations/auto_11_create_media_library_table.stub similarity index 81% rename from database/migrations/2024_04_11_000000_create_media_library_table.php rename to stubs/database/migrations/auto_11_create_media_library_table.stub index 5a60323a..f65a7b84 100644 --- a/database/migrations/2024_04_11_000000_create_media_library_table.php +++ b/stubs/database/migrations/auto_11_create_media_library_table.stub @@ -12,6 +12,10 @@ public function up(): void { Schema::create('media', function (Blueprint $table) { $table->id(); + if (config('fila-cms.multitenancy')) { + $table->unsignedBigInteger(config('fila-cms.tenant_id_field'))->nullable(); + $table->foreign(config('fila-cms.tenant_id_field'))->references('id')->on('tenants')->onDelete('cascade'); + } $table->unsignedBigInteger('parent_id')->nullable(); $table->boolean('is_folder'); $table->string('filename')->nullable(); diff --git a/database/migrations/2024_04_12_000000_create_user_logins_table.php b/stubs/database/migrations/auto_12_create_user_logins_table.stub similarity index 100% rename from database/migrations/2024_04_12_000000_create_user_logins_table.php rename to stubs/database/migrations/auto_12_create_user_logins_table.stub diff --git a/database/migrations/2024_04_19_000000_add_soft_delete_to_users.php b/stubs/database/migrations/auto_13_add_soft_delete_to_users.stub similarity index 100% rename from database/migrations/2024_04_19_000000_add_soft_delete_to_users.php rename to stubs/database/migrations/auto_13_add_soft_delete_to_users.stub diff --git a/database/migrations/2024_04_19_000000_create_settings_table.php b/stubs/database/migrations/auto_14_create_settings_table.stub similarity index 70% rename from database/migrations/2024_04_19_000000_create_settings_table.php rename to stubs/database/migrations/auto_14_create_settings_table.stub index 63c08961..1b23d8f2 100644 --- a/database/migrations/2024_04_19_000000_create_settings_table.php +++ b/stubs/database/migrations/auto_14_create_settings_table.stub @@ -11,6 +11,10 @@ public function up(): void { Schema::create('settings', function ($table) { $table->id(); + if (config('fila-cms.multitenancy')) { + $table->unsignedBigInteger(config('fila-cms.tenant_id_field'))->nullable(); + $table->foreign(config('fila-cms.tenant_id_field'))->references('id')->on('tenants')->onDelete('cascade'); + } $table->string('key')->unique(); $table->text('value')->nullable(); $table->foreignId('user_id')->nullable()->references('id')->on('users'); diff --git a/database/migrations/2024_04_22_000000_create_short_urls_table.php b/stubs/database/migrations/auto_15_create_short_urls_table.stub similarity index 100% rename from database/migrations/2024_04_22_000000_create_short_urls_table.php rename to stubs/database/migrations/auto_15_create_short_urls_table.stub diff --git a/database/migrations/2024_04_25_000000_create_forms_table.php b/stubs/database/migrations/auto_16_create_forms_table.stub similarity index 77% rename from database/migrations/2024_04_25_000000_create_forms_table.php rename to stubs/database/migrations/auto_16_create_forms_table.stub index ecc65b67..0a943f97 100644 --- a/database/migrations/2024_04_25_000000_create_forms_table.php +++ b/stubs/database/migrations/auto_16_create_forms_table.stub @@ -14,6 +14,10 @@ public function up(): void $table->id(); $table->string('title'); $table->string('slug'); + if (config('fila-cms.multitenancy')) { + $table->unsignedBigInteger(config('fila-cms.tenant_id_field'))->nullable(); + $table->foreign(config('fila-cms.tenant_id_field'))->references('id')->on('tenants')->onDelete('cascade'); + } $table->json('notification_emails')->nullable(); $table->boolean('only_for_logged_in')->default(false); $table->string('confirmation_title')->nullable(); diff --git a/database/migrations/2024_04_25_000001_create_form_entries_table.php b/stubs/database/migrations/auto_17_create_form_entries_table.stub similarity index 100% rename from database/migrations/2024_04_25_000001_create_form_entries_table.php rename to stubs/database/migrations/auto_17_create_form_entries_table.stub diff --git a/database/migrations/2024_04_26_000000_create_menus_table.php b/stubs/database/migrations/auto_18_create_menus_table.stub similarity index 69% rename from database/migrations/2024_04_26_000000_create_menus_table.php rename to stubs/database/migrations/auto_18_create_menus_table.stub index 9cd6d867..4ef263d6 100644 --- a/database/migrations/2024_04_26_000000_create_menus_table.php +++ b/stubs/database/migrations/auto_18_create_menus_table.stub @@ -12,6 +12,10 @@ public function up(): void { Schema::create('menus', function (Blueprint $table) { $table->id(); + if (config('fila-cms.multitenancy')) { + $table->unsignedBigInteger(config('fila-cms.tenant_id_field'))->nullable(); + $table->foreign(config('fila-cms.tenant_id_field'))->references('id')->on('tenants')->onDelete('cascade'); + } $table->string('name'); $table->string('note')->nullable(); $table->softDeletes(); diff --git a/database/migrations/2024_04_26_000001_create_menu_items_table.php b/stubs/database/migrations/auto_19_create_menu_items_table.stub similarity index 100% rename from database/migrations/2024_04_26_000001_create_menu_items_table.php rename to stubs/database/migrations/auto_19_create_menu_items_table.stub diff --git a/database/migrations/2024_05_03_043004_create_job_batches_table.php b/stubs/database/migrations/auto_20_create_job_batches_table.stub similarity index 100% rename from database/migrations/2024_05_03_043004_create_job_batches_table.php rename to stubs/database/migrations/auto_20_create_job_batches_table.stub diff --git a/database/migrations/2024_05_03_043010_create_notifications_table.php b/stubs/database/migrations/auto_21_create_notifications_table.stub similarity index 100% rename from database/migrations/2024_05_03_043010_create_notifications_table.php rename to stubs/database/migrations/auto_21_create_notifications_table.stub diff --git a/database/migrations/2024_05_08_000000_create_user_sso_links_table.php b/stubs/database/migrations/auto_22_create_user_sso_links_table.stub similarity index 86% rename from database/migrations/2024_05_08_000000_create_user_sso_links_table.php rename to stubs/database/migrations/auto_22_create_user_sso_links_table.stub index e512b97c..298e16d7 100644 --- a/database/migrations/2024_05_08_000000_create_user_sso_links_table.php +++ b/stubs/database/migrations/auto_22_create_user_sso_links_table.stub @@ -15,8 +15,8 @@ public function up(): void $table->string('driver'); $table->foreignId('user_id')->references('id')->on('users')->cascadeOnDelete(); $table->string('provider_id'); - $table->string('provider_token'); - $table->string('provider_refresh_token')->nullable(); + $table->text('provider_token'); + $table->text('provider_refresh_token')->nullable(); $table->timestamps(); }); } diff --git a/database/migrations/2024_05_17_000000_create_authorables.php b/stubs/database/migrations/auto_23_create_authorables.stub similarity index 100% rename from database/migrations/2024_05_17_000000_create_authorables.php rename to stubs/database/migrations/auto_23_create_authorables.stub diff --git a/database/migrations/2024_05_24_000000_create_link_checks_table.php b/stubs/database/migrations/auto_24_create_link_checks_table.stub similarity index 100% rename from database/migrations/2024_05_24_000000_create_link_checks_table.php rename to stubs/database/migrations/auto_24_create_link_checks_table.stub diff --git a/database/migrations/2024_07_24_000000_create_health_tables.php b/stubs/database/migrations/auto_25_create_health_tables.stub similarity index 100% rename from database/migrations/2024_07_24_000000_create_health_tables.php rename to stubs/database/migrations/auto_25_create_health_tables.stub diff --git a/stubs/database/migrations/create_content_model.stub b/stubs/database/migrations/create_content_model.stub index 08446813..796c6f49 100644 --- a/stubs/database/migrations/create_content_model.stub +++ b/stubs/database/migrations/create_content_model.stub @@ -11,6 +11,10 @@ return new class () extends Migration { { Schema::create('{{ table }}', function (Blueprint $table) { $table->id(); + if (config('fila-cms.multitenancy')) { + $table->unsignedBigInteger(config('fila-cms.tenant_id_field'))->nullable(); + $table->foreign(config('fila-cms.tenant_id_field'))->references('id')->on('tenants')->onDelete('cascade'); + } $table->string('title'); $table->string('slug'); $table->boolean('is_draft')->default(true);