Laragear / WebAuthn

Authenticate users with Passkeys: fingerprints, patterns and biometric data.
MIT License
305 stars 37 forks source link

[2.x] Migration throws access violation: 1059 Identifier name is too long #73

Closed codebarista closed 7 months ago

codebarista commented 7 months ago

PHP & Platform

8.3.3 - Linux aarch64

Database

MariaDB 11.3.2

Laravel version

10.48.3

Have you done this?

Expectation

Migrate create_webauthn_credentials

Description

Table index names have a maximum length of 64 characters. The relevant generated index name is 66 characters long:

webauthn_credentials_authenticatable_type_authenticatable_id_index

Maybe this is more of an issue for laragear/meta-model

https://github.com/Laragear/WebAuthn/blob/c75a373143f226e6914301229e512905766099e3/src/Migrations/WebAuthnAuthenticationMigration.php#L21

A possible workaround is to shorten the table name in AppServiceProvider before run the migration:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        \Laragear\WebAuthn\Models\WebAuthnCredential::$useTable = 'webauthn';

    }
}

However, this is not so elegant. The max length also applies to MySQL or PostgreSQL.

Reproduction

php artisan webauthn:install;
php artisan migrate;

Stack trace & logs

2024_03_15_173020_create_webauthn_credentials  6ms FAIL

Illuminate\Database\QueryException 

SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'webauthn_credentials_authenticatable_type_authenticatable_id_index' is too long (Connection: mariadb, SQL: alter table `webauthn_credentials` add index `webauthn_credentials_authenticatable_type_authenticatable_id_index`(`authenticatable_type`, `authenticatable_id`))

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:829
    825▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    826▕                 );
    827▕             }
    828▕ 
  ➜ 829▕             throw new QueryException(
    830▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    831▕             );
    832▕         }
    833▕     }

      +45 vendor frames 

  46  artisan:35
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))