singlestore-labs / singlestoredb-laravel-driver

The official SingleStore Laravel driver.
https://github.com/singlestore-labs/singlestore-laravel-driver
Apache License 2.0
223 stars 22 forks source link

Adding sparse column with after statement generates the wrong query #18

Closed miguilimzero closed 2 years ago

miguilimzero commented 2 years ago

I'm currently trying to run a migration on project, but it seems the driver is currently generating a wrong query. From what I understand it seems the "sparse" term is being added before the , while it should be added after the "add ... text null".

Migration code:

Schema::table('users', function (Blueprint $table) {
            $table->text('two_factor_secret')
                    ->after('password')
                    ->nullable()->sparse();

            $table->text('two_factor_recovery_codes')
                    ->after('two_factor_secret')
                    ->nullable()->sparse();
});

Generated query:

alter table `users` add `two_factor_secret` text null after `password` sparse, add `two_factor_recovery_codes` text null after `two_factor_secret` sparse

Error message:

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 'sparse, add `two_factor_recovery_codes` text null after `two_factor_secret` spar' at line 1 (SQL: alter table `users` add `two_factor_secret` text null after `password` sparse, add `two_factor_recovery_codes` text null after `two_factor_secret` sparse)
aarondfrancis commented 2 years ago

Hey this was a great catch, thanks for posting the issue. There were actually two issues that I found (and fixed!) while looking into this.

You can check the PR, but in short I was adding the modifiers out of order so Laravel was generating bad statements because of that. Should be fixed now, cutting a new release!

miguilimzero commented 2 years ago

What a fast fix! Thanks @aarondfrancis