Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly publish migrations on install #191

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

36 changes: 0 additions & 36 deletions database/migrations/2024_05_14_000000_add_taxonomy_code.php

This file was deleted.

44 changes: 0 additions & 44 deletions database/migrations/2024_05_17_000001_adjust_page_authors.php

This file was deleted.

This file was deleted.

17 changes: 11 additions & 6 deletions src/Providers/FilaCmsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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);
Expand Down Expand Up @@ -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(
Expand Down
36 changes: 36 additions & 0 deletions stubs/database/migrations/auto_01_create_tenants_table.stub
Original file line number Diff line number Diff line change
@@ -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 {
/**
* Run the migrations.
*/
public function up(): void
{
if (!config('fila-cms.multitenancy')) {
return;
}
Schema::create('tenants', function (Blueprint $table) {
$table->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');
}
};
33 changes: 33 additions & 0 deletions stubs/database/migrations/auto_02_create_tenant_members_table.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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
{
if (!config('fila-cms.multitenancy')) {
return;
}
Schema::create('tenant_members', function (Blueprint $table) {
$table->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');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading
Loading