Skip to content

Prevent duplicate migrations when running telescope:install#1701

Draft
JoshSalway wants to merge 6 commits intolaravel:5.xfrom
JoshSalway:fix/install-duplicate-migrations-clean
Draft

Prevent duplicate migrations when running telescope:install#1701
JoshSalway wants to merge 6 commits intolaravel:5.xfrom
JoshSalway:fix/install-duplicate-migrations-clean

Conversation

@JoshSalway
Copy link
Copy Markdown

@JoshSalway JoshSalway commented Mar 22, 2026

Summary

Running telescope:install multiple times creates duplicate migration files with different timestamps, causing "table already exists" errors on php artisan migrate.

Fixes #1589

Prior attempts

This issue has been submitted twice before, and both were closed:

This PR directly addresses both concerns.

Problem

Each run of telescope:install publishes migration files with fresh timestamps. After running it twice:

database/migrations/2026_03_19_000000_create_telescope_entries_table.php
database/migrations/2026_03_19_000001_create_telescope_entries_table.php

Running php artisan migrate then fails:

SQLSTATE: Table 'telescope_entries' already exists

This commonly happens when developers re-run the install command after pulling updates or when setting up a project from scratch with existing migrations.

Solution

Addressing #1634 (code volume concern): The entire fix is a single migrationExists() method — one glob() call using the *_create_telescope_entries_table.php pattern. This is the same pattern Laravel's own framework uses in its install commands (e.g., Pulse, Pennant). The check is added with a single if guard around the existing vendor:publish call. No new dependencies, no architectural changes.

Addressing #1678 (lacking explanation and tests): This PR includes 3 automated tests covering the detection logic:

  1. test_migration_exists_returns_false_when_no_migration_present — fresh install proceeds normally
  2. test_migration_exists_returns_true_when_migration_present — repeat install skips migration publishing
  3. test_migration_exists_returns_false_when_directory_does_not_exist — edge case where migrations directory doesn't exist yet

Before / After

Scenario Before After
First telescope:install Migration published Migration published (unchanged)
Second telescope:install Duplicate migration created Migration publishing skipped
php artisan migrate after double install "table already exists" error Runs cleanly

Why this doesn't break anything

  • The check only runs during telescope:install, not during normal application execution
  • If the migration file exists (regardless of timestamp prefix), publishing is skipped — this is purely additive
  • If the migrations directory doesn't exist yet, the check returns false and publishing proceeds as normal
  • The glob pattern matches Laravel's own convention used across first-party packages

Running telescope:install multiple times creates duplicate migration
files with different timestamps, which causes "table already exists"
errors during migration. The install command now checks if the
telescope migration already exists before publishing it.

Fixes laravel#1589

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

Josh Salway and others added 5 commits March 28, 2026 13:39
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Redirect app, config, database, and bootstrap paths to a temp directory
so telescope:install does not publish files into the shared testbench
skeleton. This was causing all other tests to fail with
"Class App\Providers\TelescopeServiceProvider not found".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add minimal composer.json with PSR-4 autoload to the temp directory and
use setBasePath() instead of individual path overrides. This resolves
the RuntimeException: Unable to detect application namespace error that
occurs because getNamespace() reads composer.json from the base path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The full telescope:install command requires config/app.php, composer.json,
and bootstrap/providers.php at the app base path, which is fragile to set
up across all Laravel versions in the CI matrix. Since the PR feature is
the migrationExists() check, test that method directly via reflection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

telescope:install create duplicate migrations

1 participant