plank / laravel-metable

A package for handling arbitrary data in Laravel 5 applications
MIT License
281 stars 42 forks source link

SQL syntax on $table->rawIndex on v6 #103

Closed vesper8 closed 6 months ago

vesper8 commented 6 months ago

Hiya!

I'm upgrading to 6.0.2 and running into this error:

Illuminate\Database\QueryException

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key, value(255))' at line 1 (Connection: mysql, SQL: alter table `meta` add index `value_string_prefix_index`(metable_type, key, value(255)))

  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▕     }

      +9 vendor frames

  10  migrations/2024_04_14_000000_add_meta_search_columns.php:16
      Illuminate\Support\Facades\Facade::__callStatic("table")
      +36 vendor frames

  47  artisan:35

This line is the culprit:

$table->rawIndex(
    "metable_type, key, value($stringIndexLength)",
    'value_string_prefix_index'
);
mysql --version
mysql  Ver 8.3.0 for macos14.2 on arm64 (Homebrew)
frasmage commented 6 months ago

doh, unescaped reserved words in the field name! Thanks for bringing this to my attention!

frasmage commented 6 months ago

6.0.3 released with a fix