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

TypeError on generate migration files #79

Closed
dadkhah-dev opened this issue Feb 16, 2022 · 9 comments
Closed

TypeError on generate migration files #79

dadkhah-dev opened this issue Feb 16, 2022 · 9 comments
Assignees

Comments

@dadkhah-dev
Copy link

database.php

'rwsn_sqlsrv' => [
            'driver' => 'sqlsrv',
            'url' => env('DATABASE_URL_RWSN_SQLSRV'),
            'host' => env('DB_HOST_RWSN_SQLSRV', 'localhost'),
            'port' => env('DB_PORT_RWSN_SQLSRV', '1433'),
            'database' => env('DB_DATABASE_RWSN_SQLSRV', 'forge'),
            'username' => env('DB_USERNAME_RWSN_SQLSRV', 'forge'),
            'password' => env('DB_PASSWORD_RWSN_SQLSRV', ''),
            'schema' => env('DB_SCHEMA_RWSN_SQLSRV', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
        ],

php artisan migrate:generate -c rwsn_sqlsrv

Using connection: rwsn_sqlsrv


   TypeError 

  MigrationsGenerator\DBAL\Mapper\ViewMapper::makeView(): Argument #2 ($sql) must be of type string, null given, called in /var/www/html/server/niyam/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Mapper/ViewMapper.php on line 60

  at vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Mapper/ViewMapper.php:77
     73▕ 
     74▕     /**
     75▕      * @throws \Doctrine\DBAL\Exception
     76▕      */
 77    private static function makeView(string $name, string $sql): View
     78▕     {
     79▕         // trim quotes
     80▕         $unquotedName = str_replace(['`', '"', '[', ']'], '', $name);
     81▕ 

      +3 vendor frames 
  4   [internal]:0
      MigrationsGenerator\DBAL\Schema::MigrationsGenerator\DBAL\{closure}()

      +18 vendor frames 
  23  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
@kitloong kitloong self-assigned this Feb 18, 2022
@kitloong kitloong added the wip label Feb 18, 2022
@kitloong
Copy link
Owner

Hi @omidd1315

Thank you for reporting.

Could you please provide the View SQL that you are trying to generate?
Also, please provide the doctrine/dbal version by

composer info doctrine/dbal

It seems the error is caused by the generator trying to generate null view SQL.

I want to reproduce the error and check the root cause before adding the null check.

@rsimonru
Copy link

Hello.

I have the a very similar issue with MySQL connection. I'd tried generate all tables in DB excluding some and generate only one table, with the same result. As you can see, when I try to generate all tables, return message with the list of tables (it's reading OK DB), but fail with error below


php artisan migrate:generate --ignore="users,password_resets,failed_jobs,personal_access_tokens,sessions"
Using connection: mysql

Generating migrations for: address, address_type, address_type_address, adidas_liq, aecoc, analytics, analytics_detail, analytics_groups, analytics_groups_ca, analytics_inputs, bagents, bagents_commissions, bagents_conditions, banks, banks_accounts, banks_accounts_companies, banks_accounts_movements, budgets, budgets_detail, budgets_detail_copy1, budgets_distribution, carriers, carriers_orders, carriers_services, carriers_states, carriers_suscribers, class_orders, companies, contable_accounts, contacts, countries, customers, customers_credit, customers_diposed, customers_payment, customers_webshops, document_sequentials, document_type, document_type_documents, documents_cancelled_products, employees, entities_files, errors_notifications, financial_companies, financial_rates, financial_rates_values, groups, issues, issues_lines, log_extractions_rules, log_locations, log_locations_blocked, log_products_assigned, log_spaces, log_spaces_types, log_stock_movements, log_stock_movements_products, log_stock_movements_types, log_workorders, log_workorders_products, log_workorders_products_details, log_workorders_types, logistics_actions, logs, logs_customerscredit, logs_directdebit, logs_methods, logs_wservices, maestro_adidas2021, media_borrar, menus, model_has_permissions, model_has_roles, notifications, notifications_recipients, notifications_smc, notifications_spooler, oauth_access_tokens, oauth_auth_codes, oauth_clients, oauth_personal_access_clients, oauth_refresh_tokens, pack, pack_contents, package_types, parameters, parameters_categories, paymenttype, paymenttype_web, permissions, powershop_formaspago, powershop_historico_stock, powershop_movimientos, powershop_movimientos_alb, powershop_movimientos_old, powershop_msi, powershop_pagos, powershop_partidos, powershop_payments_type, powershop_sin_pagos, powershop_stock, powershop_temporadas, powershops_tickets, products, products_brands, products_canals, products_catalogs, products_catalogs_detail, products_compound, products_costs, products_families, products_genders, products_parent, products_parent_canals, products_parent_media, products_rates, products_rates_products, products_rates_products_history, products_seasons, products_sizes, products_sizes_groups, products_sizes_type, products_stock, products_stock_month, products_subfamilies, products_type, products_wac, products_wac_bak, products_wac_history, projects, projects_agrupations, projects_change, projects_copy1, projects_distribution, projects_distribution_detail, projects_distribution_detail_bak, projects_groups, projects_groups_stages, provinces, psp, purchase_invoices, purchase_invoices_products, purchase_invoices_products_dist, purchase_invoices_products_dist_bak, purchase_notes, purchase_notes_products, purchase_orders, purchase_orders_products, purchases_documents_payments, ranges, ranges_products, ranges_stores, role_has_permissions, roles, sales_budgets, sales_budgets_products, sales_documents_payments, sales_documents_payments_dist, sales_invoices, sales_invoices_products, sales_notes, sales_notes_bagents, sales_notes_products, sales_notes_shipments, sales_orders, sales_orders_bagents, sales_orders_canals, sales_orders_products, sales_tickets, sales_tickets_payments, sales_tickets_products, sec_b2b_catalogs, sec_companies, sec_customers, sec_documents, sec_groups, sec_logistics, sec_menus, sec_projects, sec_roles, sec_stores, sec_users_actions, shoppingcarts, shoppingcarts_products, states, states_detail, states_documents, states_register, states_register_detail, stores, stores_paymenttypes, stores_printers, stores_sm, suppliers, suppliers_payment, supply_notes, supply_notes_products, supply_orders, supply_orders_products, tax_types, thirdparties, tmp_sales_notes_import, towns, users_actions, users_signings, virtuals_w, warehouses, warehouses_suscribers, webshops, webshops_states, work_centers, workshops, worksorders, worksorders_attachments, worksorders_products, worksorders_types, products_view, sizes_view, stock_available_view, stock_in_process

Do you want to log these migrations in the migrations table? (yes/no) [yes]:

Next Batch Number is: 1. We recommend using Batch Number 0 so that it becomes the "first" migration [Default: 0] [0]:

2

Setting up Tables and Index Migrations

TypeError

Argument 1 passed to MigrationsGenerator\Generators\Blueprint\SchemaBlueprint::__construct() must be of the type string, null given, called in C:\Users\Roberto\Desarrollo\Web-GIT\smc-b2b\vendor\kitloong\laravel-migrations-generator\src\MigrationsGenerator\Generators\TableMigration.php on line 143

at C:\Users\Roberto\Desarrollo\Web-GIT\smc-b2b\vendor\kitloong\laravel-migrations-generator\src\MigrationsGenerator\Generators\Blueprint\SchemaBlueprint.php:33
29▕ * @param string $connection Connection name.
30▕ * @param string $table Table name.
31▕ * @param string $schemaBuilder SchemaBuilder name.
➜ 33▕ public function __construct(string $connection, string $table, string $schemaBuilder)
34▕ {
35▕ $this->connection = $connection;
36▕ $this->table = $table;
37▕ $this->schemaBuilder = $schemaBuilder;

1 C:\Users\Roberto\Desarrollo\Web-GIT\smc-b2b\vendor\kitloong\laravel-migrations-generator\src\MigrationsGenerator\Generators\TableMigration.php:143
MigrationsGenerator\Generators\Blueprint\SchemaBlueprint::__construct("address", "create")

2 C:\Users\Roberto\Desarrollo\Web-GIT\smc-b2b\vendor\kitloong\laravel-migrations-generator\src\MigrationsGenerator\Generators\TableMigration.php:41
MigrationsGenerator\Generators\TableMigration::getSchemaBlueprint(Object(Doctrine\DBAL\Schema\Table), "create")

@rsimonru
Copy link

I forget some data:
PHP 7.4, Laravel 8, MySQL 5.7 on Windows 11. Do you need more info?

@kitloong
Copy link
Owner

kitloong commented Feb 24, 2022

Hi @rsimonru , thank you for reporting.

PHP 7.4, Laravel 8, MySQL 5.7 on Windows 11

Do you have this issue if you try generation on a fresh new Laravel 8?
The method to gets the connection name is identical with

use Illuminate\Support\Facades\DB;

// If your connection name is 'mysql'
DB::connection('mysql')->getName(); // Output: mysql

In normal circumstances, the connection name is not null.

on a fresh new Laravel 8

If you have the same issue I shall proceed with the same step to reproduce the error.

@rsimonru
Copy link

Thanks.
I installed a fresh Laravel project as you suggest and work fine. After check my old project, the problem was because a custom DB provider included. Disabling this component, work fine too.

@collinticer
Copy link

Hello,

We're experiencing a similar issue as above. We have a read-only Laravel application that is for viewing data within a legacy database. We were attempting to generate migrations based on that database using this package. We only use a portion of the tables, and none of the existing views. So I thought using the --skip-views option would be the way to go.

I should also mention I had originally tried without using the --skip-views option and received the same error so that was what caused me to think I needed to use that option.

Versions:

  • Laravel: 5.7.29
  • PHP: 7.3.19

However, when I run php artisan migrate:generate --tables="Accounts,Activity" --skip-views I get the following output. And it doesn't appear any migration files are actually being generated whether they're tables or views.

Using connection: sqlsrv

Generating migrations for: 

 Do you want to log these migrations in the migrations table? (yes/no) [yes]:
 > no

Setting up Tables and Index Migrations

Setting up Views Migrations

   Symfony\Component\Debug\Exception\FatalThrowableError  : Argument 2 passed to MigrationsGenerator\DBAL\Mapper\ViewMapper::makeView() must be of the type string, null given, called in /var/www/laravel/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Mapper/ViewMapper.php on line 68

  at /var/www/laravel/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Mapper/ViewMapper.php:77
    73| 
    74|     /**
    75|      * @throws \Doctrine\DBAL\Exception
    76|      */
  > 77|     private static function makeView(string $name, string $sql): View
    78|     {
    79|         // trim quotes
    80|         $unquotedName = str_replace(['`', '"', '[', ']'], '', $name);
    81| 

  Exception trace:

  1   MigrationsGenerator\DBAL\Mapper\ViewMapper::makeView("ArchivesView")
      /var/www/laravel/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Mapper/ViewMapper.php:68

  2   MigrationsGenerator\DBAL\Mapper\ViewMapper::makeSQLSrvView(Object(Doctrine\DBAL\Schema\View))
      /var/www/laravel/vendor/kitloong/laravel-migrations-generator/src/MigrationsGenerator/DBAL/Mapper/ViewMapper.php:27

  Please use the argument -v to see more details.

We're thinking to backup, remove the views entirely, and try again since they are no longer referenced at all. But wanted to add my additional info here in case it is needed to troubleshoot this further.

Thanks!

@kitloong
Copy link
Owner

Hi @collinticer , thank you for the detailed explanation and I am sorry for my late reply.

I am aware of this type error and the reason I keep this issue open is that I currently can't find a good way to fix the issue.

This package has tight relation with doctrine/dbal, the complaining argument is in fact value from the doctrine/dbal, which should be a non-null string.

I suspect the package has a different type definition in the previous version and that's why we are seeing this issue.

Could you please provide the doctrine/dbal version by

composer info doctrine/dbal

I will proceed to the fix if I am able to find what is really going on with the type error.

@collinticer
Copy link

Hey @kitloong - thanks for looking into this!

I've been able to get past this error by commenting out all the associated code dealing with views from /MigrationGenerator/MigrateGenerateCommand.php, since we weren't needing migrations for the views at all. So this is not a breaking issue for us at the moment and we have all our migrations generated now which is great! But I'm happy to contribute any additional feedback you may need.

Following is the version output of composer info doctrine/dbal:

name     : doctrine/dbal
descrip. : Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.
keywords : abstraction, database, db2, dbal, mariadb, mssql, mysql, oci8, oracle, pdo, pgsql, postgresql, queryobject, sasql, sql, sqlanywhere, sqlite, sqlserver, sqlsrv
versions : * 2.13.8
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://www.doctrine-project.org/projects/dbal.html
source   : [git] https://github.com/doctrine/dbal.git dc9b3c3c8592c935a6e590441f9abc0f9eba335b
dist     : [zip] https://api.github.com/repos/doctrine/dbal/zipball/dc9b3c3c8592c935a6e590441f9abc0f9eba335b dc9b3c3c8592c935a6e590441f9abc0f9eba335b
path     : /var/www/laravel/vendor/doctrine/dbal
names    : doctrine/dbal

Let me know what else you need from me.

@kitloong
Copy link
Owner

kitloong commented May 6, 2022

Hi @collinticer

Thank you for providing the details, it helps a lot in my investigation.

It turns out in sqlsrv, view definition may be NULL if one does not permission or, the definition is encrypted.
https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-sql-modules-transact-sql?view=sql-server-ver15

I added NULL check to filter the empty definition.
On top of that, thanks for mention, --skip-views should not execute Views-related code, I have fixed that too.

All fixed above were released in v5.2.1.

Thank you for making this package better!

kitloong added a commit that referenced this issue May 21, 2022
@kitloong kitloong removed the wip label Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants