laravel / telescope

An elegant debug assistant for the Laravel framework.
https://laravel.com/docs/telescope
MIT License
4.77k stars 560 forks source link

Use configurable database table names #1475

Closed izemomar closed 2 months ago

izemomar commented 2 months ago

Currently, Laravel Telescope uses static table names throughout its codebase (telescope_entries, telescope_monitoring, telescope_entries_tags). This presents a challenge when using Telescope with multiple Laravel applications sharing the same database.

For example, consider a scenario where we have:

In this situation, it's crucial to maintain data separation between the two applications. Without configurable table names, data from both applications would be mixed within the default Telescope tables, making analysis difficult.

To address this issue, i propose introducing a configuration option within the telescope.php configuration file. This option would allow developers to specify custom table names for Telescope as follows:

return [
    'migrations' => [
         "entries" => "telescope_entries",
         "tags" => "telescope_entries_tags",
         "monitoring" => "telescope_monitoring",
    ],
];

Developers can then utilize these custom table names in migration files and any other hardcoded instances, enhancing flexibility and enabling better data separation.

<?php

return new class extends Migration
{
    /**
     * Get the migration connection name.
     */
    public function getConnection(): ?string
    {
        return config('telescope.storage.database.connection');
    }

    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $schema = Schema::connection($this->getConnection());

        $schema->create(config('telescope.migrations.entries'), function (Blueprint $table) {
              //
        });

        $schema->create(config('telescope.migrations.tags'), function (Blueprint $table) {
              //
        });

        $schema->create(config('telescope.migrations.monitoring'), function (Blueprint $table) {
            //
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        $schema = Schema::connection($this->getConnection());

        $schema->dropIfExists(config('telescope.migrations.monitoring'));
        $schema->dropIfExists(config('telescope.migrations.monitoring'));
        $schema->dropIfExists(config('telescope.migrations.monitoring'));
    }
};

I kindly request the approval to implement this enhancement. I am prepared to contribute by creating a pull request to add this customization feature

driesvints commented 2 months ago

Thanks. Right now we don't have plans for this sorry.