Robert-2 / Robert2

Application web de gestion de parc de matériel destiné à la location ou au prêt
https://robertmanager.org
Other
42 stars 13 forks source link

Problème de migration utilisant les préfixes de table #288

Closed Tuxem closed 3 years ago

Tuxem commented 3 years ago

Bonjour,

J'ai mit à jour en suivant de la 14.3 vers la 15.0 et malgré le fait de n'avoir eut aucune erreurs dans la migration de la BDD, j'ai cette erreur lorsque je charge l'interface :+1:

#### Message de l'erreur (500) :

`SQLSTATE[42S02]: Base table or view not found: 1146 Table 'robert2.robert2_event_technicians' doesn't exist (SQL: select * from `robert2_event_technicians` where `robert2_event_technicians`.`event_id` in (10, 15, 16, 19, 20, 21, 22, 23, 24, 25) order by `start_time` asc)`

#### Fichier :

`src/vendor/illuminate/database/Connection.php, line 692.`
#### Trace de la pile :
>! Details
```log
- 0: Illuminate\Database\Connection::runQueryCallback
File: src/vendor/illuminate/database/Connection.php, line 652
- 1: Illuminate\Database\Connection::run
File: src/vendor/illuminate/database/Connection.php, line 360
- 2: Illuminate\Database\Connection::select
File: src/vendor/illuminate/database/Query/Builder.php, line 2350
- 3: Illuminate\Database\Query\Builder::runSelect
File: src/vendor/illuminate/database/Query/Builder.php, line 2338
- 4: Illuminate\Database\Query\Builder::Illuminate\Database\Query\{closure}
File: src/vendor/illuminate/database/Query/Builder.php, line 2872
- 5: Illuminate\Database\Query\Builder::onceWithColumns
File: src/vendor/illuminate/database/Query/Builder.php, line 2339
- 6: Illuminate\Database\Query\Builder::get
File: src/vendor/illuminate/database/Eloquent/Builder.php, line 602
- 7: Illuminate\Database\Eloquent\Builder::getModels
File: src/vendor/illuminate/database/Eloquent/Builder.php, line 586
- 8: Illuminate\Database\Eloquent\Builder::get
File: src/vendor/illuminate/database/Eloquent/Relations/Relation.php, line 188
- 9: Illuminate\Database\Eloquent\Relations\Relation::get
File: src/vendor/illuminate/database/Eloquent/Relations/Relation.php, line 153
- 10: Illuminate\Database\Eloquent\Relations\Relation::getEager
File: src/vendor/illuminate/database/Eloquent/Builder.php, line 650
- 11: Illuminate\Database\Eloquent\Builder::eagerLoadRelation
File: src/vendor/illuminate/database/Eloquent/Builder.php, line 619
- 12: Illuminate\Database\Eloquent\Builder::eagerLoadRelations
File: src/vendor/illuminate/database/Eloquent/Builder.php, line 587
- 13: Illuminate\Database\Eloquent\Builder::get
File: src/App/Controllers/EventController.php, line 47
- 14: Robert2\API\Controllers\EventController::getAll
File: src/vendor/slim/slim/Slim/Handlers/Strategies/RequestResponse.php, line 43
- 15: Slim\Handlers\Strategies\RequestResponse::__invoke
File: src/vendor/slim/slim/Slim/Routing/Route.php, line 384
- 16: Slim\Routing\Route::handle
File: src/vendor/slim/slim/Slim/MiddlewareDispatcher.php, line 81
- 17: Slim\MiddlewareDispatcher::handle
File: src/vendor/slim/slim/Slim/MiddlewareDispatcher.php, line 81
- 18: Slim\MiddlewareDispatcher::handle
File: src/vendor/slim/slim/Slim/Routing/Route.php, line 341
- 19: Slim\Routing\Route::run
File: src/vendor/slim/slim/Slim/Routing/RouteRunner.php, line 84
- 20: Slim\Routing\RouteRunner::handle
File: src/vendor/slim/slim/Slim/Middleware/BodyParsingMiddleware.php, line 68
- 21: Slim\Middleware\BodyParsingMiddleware::process
File: src/vendor/slim/slim/Slim/MiddlewareDispatcher.php, line 147
- 22: class@anonymous

Pour info, voici les logs de mise à jour :

root@robert2:/var/www/Robert2# cd server && composer install
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? 
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 0 installs, 18 updates, 0 removals
  - Upgrading cakephp/core (4.2.7 => 4.2.8): Extracting archive
  - Upgrading cakephp/utility (4.2.7 => 4.2.8): Extracting archive
  - Upgrading cakephp/datasource (4.2.7 => 4.2.8): Extracting archive
  - Upgrading firebase/php-jwt (v5.2.1 => v5.4.0): Extracting archive
  - Upgrading illuminate/macroable (v8.49.1 => v8.51.0): Extracting archive
  - Upgrading illuminate/contracts (v8.49.1 => v8.51.0): Extracting archive
  - Upgrading illuminate/collections (v8.49.1 => v8.51.0): Extracting archive
  - Upgrading illuminate/support (v8.49.1 => v8.51.0): Extracting archive
  - Upgrading illuminate/container (v8.49.1 => v8.51.0): Extracting archive
  - Upgrading illuminate/database (v8.44.0 => v8.51.0): Extracting archive
  - Upgrading illuminate/pagination (v8.44.0 => v8.51.0): Extracting archive
  - Upgrading monolog/monolog (2.2.0 => 2.3.2): Extracting archive
  - Upgrading php-di/php-di (6.3.3 => 6.3.4): Extracting archive
  - Upgrading nikic/php-parser (v4.11.0 => v4.12.0): Extracting archive
  - Upgrading phar-io/manifest (2.0.1 => 2.0.3): Extracting archive
  - Upgrading phpunit/phpunit (9.5.4 => 9.5.7): Extracting archive
  - Upgrading cakephp/database (4.2.7 => 4.2.8): Extracting archive
  - Upgrading slim/slim (4.8.0 => 4.8.1): Extracting archive
Package sebastian/resource-operations is abandoned, you should avoid using it. No replacement was suggested.
Generating autoload files
58 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
root@robert2:/var/www/Robert2/server# composer migrate
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? 
> src/vendor/robmorgan/phinx/bin/phinx --configuration=src/database/phinx.php migrate
Phinx by CakePHP - https://phinx.org.

using config file src/database/phinx.php
using config parser php
using migration paths 
 - /var/www/Robert2/server/src/database/migrations
using seed paths 
warning no environment specified, defaulting to: development
using database robert2
using table prefix robert2_
ordering by creation time

 == 20210712164748 ChangeEventAssigneesToTechnicians: migrating
 == 20210712164748 ChangeEventAssigneesToTechnicians: migrated 1.0158s

 == 20210823124640 ChangeEventDescriptionToText: migrating
 == 20210823124640 ChangeEventDescriptionToText: migrated 0.2757s

 == 20210901144538 ChangeMaterialCategoryConstraint: migrating
 == 20210901144538 ChangeMaterialCategoryConstraint: migrated 0.8239s

All Done. Took 2.1695s
root@robert2:/var/www/Robert2/server# cd ../client/
root@robert2:/var/www/Robert2/client# npm install

> yorkie@2.0.0 uninstall /var/www/Robert2/client/node_modules/yorkie
> node bin/uninstall.js

husky
uninstalling Git hooks
done

npm WARN vue-js-modal@2.0.0-rc.6 requires a peer of vue@2.6.11 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-config-airbnb@18.2.1 requires a peer of eslint-plugin-jsx-a11y@^6.4.1 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-config-airbnb@18.2.1 requires a peer of eslint-plugin-react-hooks@^4 || ^3 || ^2.3.0 || ^1.7.0 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.21.0 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/jest-haste-map/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 182 packages from 116 contributors, removed 39 packages, updated 14 packages, moved 11 packages and audited 1952 packages in 76.652s

146 packages are looking for funding
  run `npm fund` for details

found 6 vulnerabilities (1 low, 5 moderate)
  run `npm audit fix` to fix them, or `npm audit` for details
root@robert2:/var/www/Robert2/client# npm run build

> @ build /var/www/Robert2/client
> vue-cli-service build ./src/index.js

  File                          Size                                                               Gzipped

  dist/js/chunk-vendors.js      1615.73 KiB                                                        488.90 KiB
  dist/js/app.js                396.66 KiB                                                         92.18 KiB
  dist/css/app.css              147.27 KiB                                                         22.58 KiB
  dist/css/chunk-vendors.css    72.54 KiB                                                          16.25 KiB

  Images and other types of assets omitted.

 DONE  Build complete. The dist directory is ready to be deployed.
 INFO  Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html

root@robert2:/var/www/Robert2/client# cd ..
root@robert2:/var/www/Robert2# rm server/src/var/cache/routes.php 
Donov4n commented 3 years ago

Là comme ça on dirait un souci de préfixe...

Est-ce qu'il serait possible d'avoir la liste des tables dans la base robert2 (SHOW TABLES;) ?

Tuxem commented 3 years ago

Bien évidemment :)

mysql> show tables;
+----------------------------------+
| Tables_in_robert2                |
+----------------------------------+
| event_technicians                |
| phinxlog                         |
| robert2_attribute_categories     |
| robert2_attributes               |
| robert2_bills                    |
| robert2_categories               |
| robert2_companies                |
| robert2_countries                |
| robert2_documents                |
| robert2_estimates                |
| robert2_event_beneficiaries      |
| robert2_event_material_units     |
| robert2_event_materials          |
| robert2_events                   |
| robert2_groups                   |
| robert2_inventories              |
| robert2_inventory_material_units |
| robert2_inventory_materials      |
| robert2_material_attributes      |
| robert2_material_unit_states     |
| robert2_material_units           |
| robert2_materials                |
| robert2_parks                    |
| robert2_persons                  |
| robert2_settings                 |
| robert2_sub_categories           |
| robert2_taggables                |
| robert2_tags                     |
| robert2_user_settings            |
| robert2_users                    |
+----------------------------------+
30 rows in set (0.01 sec)
Donov4n commented 3 years ago

Il semble bien y avoir un souci avec la table event_technicians, qui devrait se nommer robert2_event_technicians.
=> Pour corriger le souci rapidement chez vous, il faudrait la renommer manuellement.

Après, pour ce qui est de savoir pourquoi le rename n'a pas fonctionné dans votre cas, ça ...
Effectivement, un dump pré-migration pourrait être utile pour qu'on essaie de reproduire si possible. 👍

(cc @polosson)

Tuxem commented 3 years ago

Okay, effectivement, en faisant un RENAME TABLE event_technicians TO robert2_event_technicians; ça résoud le problème, c'était tellement simple xD

Je t'envoie les dumps si vous voulez creuser le pourquoi du comment ;)

Je vous laisse gérer si vous voulez clôre ou pas l'issue. Je reste dispo si jamais :)

Donov4n commented 3 years ago

Merci pour le signalement, on va essayer de reproduire / corriger avant de fermer le ticket.

Pour le suivi / futur debug:
Je me demande si la méthode rename() de Phinx prend en compte la configuration des préfixes de table.
C'est la première fois qu'on l'utilise dans les migrations sauf erreur, donc probable qu'on ait pas remarqué le souci avant.

(cc @polosson)

polosson commented 3 years ago

Bon apparemment :

Donc je vais regarder ce que ça donne avec le dump pré-migration fourni, et tenter de reproduire ceci. Je verrai si on peut corriger nous-même ou pas...

Mais pffff, décidément ces préfixes, c'est un peu la m... à gérer lol

polosson commented 3 years ago

OK, j'ai pu reproduire le bug en local, effectivement Phinx ne semble pas tenir compte de la config pour le préfixe quand on renomme la table. Strange ! Je vais regarder un peu plus en détail, ouvrir un ticket chez Phinx, et faire un hotfix qui corrige ça "à la main" en ajoutant directement le préfixe dans le nom passé à rename()...

polosson commented 3 years ago

Voilà qui est fait pour le ticket chez Phinx : https://github.com/cakephp/phinx/issues/2018

Le hotfix arrivera cet après midi. Cheers !