joselfonseca / lighthouse-graphql-passport-auth

Add GraphQL mutations to get tokens from passport for https://lighthouse-php.com/
https://lighthouse-php-auth.com/
MIT License
229 stars 56 forks source link

How come Update Social Provider User Migration runs before Users table migration ? #86

Closed canatufkansu closed 4 years ago

canatufkansu commented 4 years ago

Hi,

First of all thank you for this great package it makes our Passport Auth very easy with Graphql.

My question is that when I try to run migrations for some reason Laravel runs

2019_11_19_000000_update_social_provider_users_table

migration before all of my main migrations so I get the following error

Undefined table: 7 ERROR: relation "users" does not exist

I think reason is my migrations starts with **2020_* but this migration is starts with 2019_11**.

canatufkansu commented 4 years ago

What I understood so far is that this migration is coming from this package. When I publish it, it copies this migration file to my app's migration folder. The migration file it copies is starts with 2019_*

When I run php artisan migrate:status, following is my migration order

root@590a178d85fd:/var/www# php artisan migrate:status
+------+-------------------------------------------------------------------------+-------+
| Ran? | Migration                                                               | Batch |
+------+-------------------------------------------------------------------------+-------+
| No   | 2014_10_12_100000_create_password_resets_table                          |       |
| No   | 2016_06_01_000001_create_oauth_auth_codes_table                         |       |
| No   | 2016_06_01_000002_create_oauth_access_tokens_table                      |       |
| No   | 2016_06_01_000003_create_oauth_refresh_tokens_table                     |       |
| No   | 2016_06_01_000004_create_oauth_clients_table                            |       |
| No   | 2016_06_01_000005_create_oauth_personal_access_clients_table            |       |
| No   | 2018_08_08_100000_create_telescope_entries_table                        |       |
| No   | 2019_11_19_000000_update_social_provider_users_table                    |       |
| No   | 2020_04_30_000001_create_media_table                                    |       |
| No   | 2020_04_30_000002_create_permissions_table                              |       |
| No   | 2020_04_30_000003_create_colors_table                                   |       |
| No   | 2020_04_30_000004_create_time_zones_table                               |       |
| No   | 2020_04_30_000005_create_currencies_table                               |       |
| No   | 2020_04_30_000006_create_consents_table                                 |       |
| No   | 2020_04_30_000007_create_user_expertise_areas_table                     |       |
| No   | 2020_04_30_000008_create_franchises_table                               |       |
| No   | 2020_04_30_000009_create_user_settings_table                            |       |
| No   | 2020_04_30_000010_create_countries_table                                |       |
| No   | 2020_04_30_000011_create_multiple_file_upload_examples_table            |       |
| No   | 2020_04_30_000012_create_listings_table                                 |       |
| No   | 2020_04_30_000013_create_offices_table                                  |       |
| No   | 2020_04_30_000014_create_brands_table                                   |       |
| No   | 2020_04_30_000015_create_users_table                                    |       |
| No   | 2020_04_30_000016_create_roles_table                                    |       |
| No   | 2020_04_30_000017_create_languages_table                                |       |
| No   | 2020_04_30_000018_create_office_user_pivot_table                        |       |
| No   | 2020_04_30_000019_create_role_user_pivot_table                          |       |
| No   | 2020_04_30_000020_create_consent_user_pivot_table                       |       |
| No   | 2020_04_30_000021_create_permission_role_pivot_table                    |       |
| No   | 2020_04_30_000022_add_relationship_fields_to_offices_table              |       |
| No   | 2020_04_30_000023_add_relationship_fields_to_brands_table               |       |
| No   | 2020_04_30_000024_add_relationship_fields_to_user_settings_table        |       |
| No   | 2020_04_30_000025_add_relationship_fields_to_user_expertise_areas_table |       |
+------+-------------------------------------------------------------------------+-------+

When I try to run the migration run this, it stucks when it comes to 2019_* migration.

Then I try to rename the file to 2020_05_02 to correct the order, this time status becomes this

root@590a178d85fd:/var/www# php artisan migrate:status
+------+-------------------------------------------------------------------------+-------+
| Ran? | Migration                                                               | Batch |
+------+-------------------------------------------------------------------------+-------+
| No   | 2014_10_12_100000_create_password_resets_table                          |       |
| No   | 2016_06_01_000001_create_oauth_auth_codes_table                         |       |
| No   | 2016_06_01_000002_create_oauth_access_tokens_table                      |       |
| No   | 2016_06_01_000003_create_oauth_refresh_tokens_table                     |       |
| No   | 2016_06_01_000004_create_oauth_clients_table                            |       |
| No   | 2016_06_01_000005_create_oauth_personal_access_clients_table            |       |
| No   | 2018_08_08_100000_create_telescope_entries_table                        |       |
| No   | 2019_11_19_000000_update_social_provider_users_table                    |       |
| No   | 2020_04_30_000001_create_media_table                                    |       |
| No   | 2020_04_30_000002_create_permissions_table                              |       |
| No   | 2020_04_30_000003_create_colors_table                                   |       |
| No   | 2020_04_30_000004_create_time_zones_table                               |       |
| No   | 2020_04_30_000005_create_currencies_table                               |       |
| No   | 2020_04_30_000006_create_consents_table                                 |       |
| No   | 2020_04_30_000007_create_user_expertise_areas_table                     |       |
| No   | 2020_04_30_000008_create_franchises_table                               |       |
| No   | 2020_04_30_000009_create_user_settings_table                            |       |
| No   | 2020_04_30_000010_create_countries_table                                |       |
| No   | 2020_04_30_000011_create_multiple_file_upload_examples_table            |       |
| No   | 2020_04_30_000012_create_listings_table                                 |       |
| No   | 2020_04_30_000013_create_offices_table                                  |       |
| No   | 2020_04_30_000014_create_brands_table                                   |       |
| No   | 2020_04_30_000015_create_users_table                                    |       |
| No   | 2020_04_30_000016_create_roles_table                                    |       |
| No   | 2020_04_30_000017_create_languages_table                                |       |
| No   | 2020_04_30_000018_create_office_user_pivot_table                        |       |
| No   | 2020_04_30_000019_create_role_user_pivot_table                          |       |
| No   | 2020_04_30_000020_create_consent_user_pivot_table                       |       |
| No   | 2020_04_30_000021_create_permission_role_pivot_table                    |       |
| No   | 2020_04_30_000022_add_relationship_fields_to_offices_table              |       |
| No   | 2020_04_30_000023_add_relationship_fields_to_brands_table               |       |
| No   | 2020_04_30_000024_add_relationship_fields_to_user_settings_table        |       |
| No   | 2020_04_30_000025_add_relationship_fields_to_user_expertise_areas_table |       |
| No   | 2020_05_02_000000_update_social_provider_users_table                    |       |
+------+-------------------------------------------------------------------------+-------+

As you can see "update_social_provider_users_table " migrations appears two times. So I get the following error

PHP Fatal error:  Cannot declare class UpdateSocialProviderUsersTable, because the name is already in use in /var/www/database/migrations/2020_05_02_000000_update_social_provider_users_table.php on line 7

It doesn't matter if I change the name or whatever. Laravel always sees the migration inside of the package which I cannot change because it is managed by the composer.

canatufkansu commented 4 years ago

I solved it and find the reason of it.

As you can see from my previous posts my users table migration starts with 2020_. Usually when I use Laravel standard Auth scaffolding this migration starts with 2014_1012 so the this packaged named it's migration 2019 according to that. For standard Laravel installation this setup runs smoothly. There is no problem with both Laravel and the Package.

But this time I used https://2019.quickadminpanel.com to jump start my development. Unfortunately QuickAdminPanel generates Users table migration with current date 2020_ so this problem occurs.

I changed my Users table migration to Laravel's standard which is 2014_10_12_000000_create_users_table everything start working.