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

php artisan migrate ❌ #1384

Closed
007by opened this issue Sep 30, 2023 · 5 comments · Fixed by #1385
Closed

php artisan migrate ❌ #1384

007by opened this issue Sep 30, 2023 · 5 comments · Fixed by #1385

Comments

@007by
Copy link

007by commented Sep 30, 2023

Jetstream Version

4.x

Jetstream Stack

Livewire

Laravel Version

v10.25.1

PHP Version

v8.1.21

Database Driver & Version

mysql 5.7

Description

php artisan migrate

INFO Preparing database.

Creating migration table .............................................................. 24ms DONE

INFO Running migrations.

2014_10_12_000000_create_users_table .................................................. 30ms DONE
2014_10_12_100000_create_password_reset_tokens_table .................................. 35ms DONE
2014_10_12_200000_add_two_factor_columns_to_users_table ............................... 21ms DONE
2019_08_19_000000_create_failed_jobs_table ............................................ 26ms DONE
2019_12_14_000001_create_personal_access_tokens_table ................................. 38ms DONE
2023_09_30_192227_create_sessions_table ............................................... 59ms DONE
2023_09_30_192437_create_sessions_table ................................................ 2ms FAIL

Illuminate\Database\QueryException

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'sessions' already exists (Connection: mysql, SQL: create table sessions (id varchar(255) not null, user_id bigint unsigned null, ip_address varchar(45) null, user_agent text null, payload longtext not null, last_activity int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

at vendor/laravel/framework/src/Illuminate/Database/Connection.php:801
797▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
798▕ );
799▕ }
800▕
➜ 801▕ throw new QueryException(
802▕ $this->getName(), $query, $this->prepareBindings($bindings), $e
803▕ );
804▕ }
805▕ }

  +9 vendor frames 

10 database/migrations/2023_09_30_192437_create_sessions_table.php:21
Illuminate\Support\Facades\Facade::__callStatic()
+24 vendor frames

35 artisan:37
Illuminate\Foundation\Console\Kernel::handle()

Steps To Reproduce

composer create-project laravel/laravel example-app

cd example-app

composer require laravel/jetstream

php artisan jetstream:install livewire

php artisan jetstream:install livewire --dark

npm install
npm run build

php artisan migrate

@jessarcher
Copy link
Member

You shouldn't call the jetstream:install command twice.

Having said that, it shouldn't create a duplicate migration. This seems to be caused by the switch to anonymous migrations which will prevent the current approach from detecting the existing migration.

@jessarcher jessarcher added the bug label Sep 30, 2023
@crynobone
Copy link
Member

crynobone commented Sep 30, 2023

You shouldn't run jetstream:install twice. This would republish the same sessiom migration using a different datetime.

This issue can be reproduced before using anonymous class but instead of query failing you'll get a duplicated class error from PHP.

@crynobone crynobone removed the bug label Sep 30, 2023
@jessarcher
Copy link
Member

@crynobone There is code in the installer that attempts to prevent the duplicate migration:

if (! class_exists('CreateSessionsTable')) {
try {
$this->call('session:table');
} catch (Exception $e) {
//
}
}

We should either make it work with anonymous migrations or remove it.

@jessarcher
Copy link
Member

We should also throw an error if Jetstream is already installed (maybe just checking for the Jetstream config file). It probably doesn't matter too much if you reinstall the same stack just with dark mode, but if you choose a different stack it would make a mess.

@crynobone
Copy link
Member

if (! class_exists('CreateSessionsTable')) {

The code exists since 0.0.1 and targeting Laravel 8 where anonymous class isn't supported/the default yet.

And running php artisan session:table manually doesn't provide any prevention before or after using anonymous class.

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 a pull request may close this issue.

3 participants