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

Migrations not respecting nullable on polygon or point types. #50201

Closed
flatcapco opened this issue Feb 22, 2024 · 8 comments
Closed

Migrations not respecting nullable on polygon or point types. #50201

flatcapco opened this issue Feb 22, 2024 · 8 comments

Comments

@flatcapco
Copy link

Laravel Version

10.45

PHP Version

8.3.3

Database Driver & Version

Mysql 8.0.3.3

Description

Nullable == false is not respected when running a new migration for the 2 column types "polygon" and "point" for a Mysql 8 table

$table->polygon('geom')->nullable(false);
$table->point('point')->nullable(false);

Steps To Reproduce

Create a migration with 2 columns:

$table->polygon('geom')->nullable(false);
$table->point('point')->nullable(false);

The columns are not set to nullable in the database.

It works if you run a DB::statement after to alter the columns
DB::statement('ALTER TABLE polygons MODIFY COLUMN geom POLYGON SRID 4326 NOT NULL;');
DB::statement('ALTER TABLE locations MODIFY COLUMN point POINT SRID 4326 NOT NULL;');

which is needed if you want to restrict your point and polygon to use an SRID value for spatial indexing: DB::Statement('CREATE SPATIAL INDEX idx_polygons_geom ON polygons(geom);');
DB::Statement('CREATE SPATIAL INDEX idx_locations_point ON locations(point);');

@driesvints
Copy link
Member

I have a feeling this will be solved in Laravel v11. Am I correct @hafezdivandari?

@hafezdivandari
Copy link
Contributor

This already works in Laravel 10. Are you trying to add these columns or modify them?

Adding

// Laravel 10
$table->polygon('geom')->srid(4326); // polygin srid 4326 not null
$table->point('point')->srid(4326);  // point srid 4326 not null

// Laravel 11
$table->geometry('geom', 'polygon', 4326); // polygin srid 4326 not null
$table->geometry('point', 'point', 4326);  // point srid 4326 not null

Modifying

On Laravel 10, you have to call Schema::useNativeSchemaOperationsIfPossible() if you have doctrine/dbal installed:

// Laravel 10
$table->polygon('geom')->srid(4326)->change(); // polygin srid 4326 not null
$table->point('point')->srid(4326)->change();  // point srid 4326 not null

// Laravel 11
$table->geometry('geom', 'polygon', 4326)->change(); // polygin srid 4326 not null
$table->geometry('point', 'point', 4326)->change();  // point srid 4326 not null

@flatcapco
Copy link
Author

Thanks but I think the nullable bug still exists in L10, what I'm seeing using the laravel 10 example:

If I follow the adding steps above it does correctly set point and polygon to "is_nullable NO"

however if srid wasn't used then the bug for ->nullable(false) still exists as its not applied to the column correctly and since srid is optional that seems strange to me.

In my case I do want to use srid so I can use your adding lines and remove my second step to enforce the srid and nullable status.

Thanks

@flatcapco
Copy link
Author

See above sorry I closed it by accident

@flatcapco flatcapco reopened this Feb 22, 2024
@driesvints
Copy link
Member

Just not add ->nullable(false) like @hafezdivandari suggested? Why can't you do that?

@flatcapco
Copy link
Author

Just not add ->nullable(false) like @hafezdivandari suggested? Why can't you do that?

adding $table->polygon('geom')->srid(4326) works.

However, if you don't specify a srid then is_nullable can only be set to false with a raw statement.

@hafezdivandari
Copy link
Contributor

It even works if you add ->nullable(false) with/without using srid. I've tested again, everything works fine on Laravel 10. I couldn't reproduce your issue.

@flatcapco
Copy link
Author

ok weirdly I can't replicate now either :/ consider it closed and me an idiot unless I can see whats changed

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

3 participants