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

No support for Laravel database prefix #67

Open
harveydobson opened this issue May 12, 2022 · 0 comments
Open

No support for Laravel database prefix #67

harveydobson opened this issue May 12, 2022 · 0 comments

Comments

@harveydobson
Copy link

harveydobson commented May 12, 2022

Within Laravel's config/database.php file, there is an option to add a prefix to database table names.

My MySQL config for example (defualt prefix is '') :

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => env('DB_PREFIX', ''),
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

However, when generating a new schema with php artisan openapi:make-schema User -m User, it looks like the prefix field isn't being honoured as it should be, as I get this error message:

 Doctrine\DBAL\Schema\SchemaException

  There is no column with name 'id' on table 'users'.

  at vendor/doctrine/dbal/src/Schema/SchemaException.php:87
     83▕      * @return SchemaException
     84▕      */
     85▕     public static function columnDoesNotExist($columnName, $table)
     86▕     {
  ➜  87▕         return new self(
     88▕             sprintf("There is no column with name '%s' on table '%s'.", $columnName, $table),
     89▕             self::COLUMN_DOESNT_EXIST
     90▕         );
     91▕     }

      +3 vendor frames
  4   [internal]:0
      Vyuldashev\LaravelOpenApi\Console\SchemaFactoryMakeCommand::Vyuldashev\LaravelOpenApi\Console\{closure}("id")

      +17 vendor frames
  22  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

My users table is actually prefixed with "auth_" so if it looked for "auth_users" it would find the correct structure.

I've looked at the code to see if I can submit a PR for this, but I can't seem to find on a quick glance, where that table name is set within the code.

harveydobson pushed a commit to harveydobson/laravel-openapi that referenced this issue May 12, 2022
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

No branches or pull requests

1 participant