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

[5.8] Revert #26454 and change default to bigIncrements in the migration stub #26472

Merged
merged 4 commits into from
Nov 11, 2018
Merged

[5.8] Revert #26454 and change default to bigIncrements in the migration stub #26472

merged 4 commits into from
Nov 11, 2018

Conversation

sisve
Copy link
Contributor

@sisve sisve commented Nov 11, 2018

The previous PR #26454 broke existing migrations by changing the behavior of the increments method. It was also incomplete; changing the primary key alone would have caused issues at the first sight of a foreign key which was still an "small" integer.

Also, keep in mind that this flag is an application-wide flag. There will be developers that think that their increments become bigIncrements and still uses increments, and there will be installations that sets this flag, ending up with code that does something unexpected (by those expecting the increments to become bigIncrements).

This is comparable to $table->string('email') that once upon a time created a 255 character large string, and then suddenly became 191 characters because some service provider (perhaps even in a third party package), used Builder::defaultStringLength(191);, and we had to go back and change all our migrations to specifically say $table->string('email', 255) to make sure that we got what we expected.

I propose a revert of #26454 and instead change the default migration file generated by php artisan make:migration ... to use bigIncrements instead. This means that all existing migrations are still working as-is, and this new behavior will only affect new migrations. It also means that the method can be changed back to increments by the developer to get the old behavior when needed.

It is my personal belief that the migration system has even stricter requirements on backward compatibility than releases in other parts of the framework. Migrations are usually written, published and then never changed. (Any change needed goes into another migration. Migrations are like ogres, they have layers...).

@sisve sisve changed the title Revert #26454 and change defult to bigIncrements in the migration slug Revert #26454 and change default to bigIncrements in the migration slug Nov 11, 2018
@sisve sisve changed the title Revert #26454 and change default to bigIncrements in the migration slug [5.8] Revert #26454 and change default to bigIncrements in the migration slug Nov 11, 2018
@sisve
Copy link
Contributor Author

sisve commented Nov 11, 2018

The failing tests are unrelated to my change, the master branch seems failing at the moment.

@sisve sisve changed the title [5.8] Revert #26454 and change default to bigIncrements in the migration slug [5.8] Revert #26454 and change default to bigIncrements in the migration stub Nov 11, 2018
@antonkomarev
Copy link
Contributor

antonkomarev commented Nov 11, 2018

Change old behavior is overkill. I agree with @sisve solution. We'd better keep it simple and just generate migrations with bigIncrements by default. It's not that much to write 3 extra letters, but it's much more obvious.

@taylorotwell taylorotwell merged commit 74c5730 into laravel:master Nov 11, 2018
@sisve sisve deleted the change-big-increments branch November 11, 2018 16:13
@hastinbe
Copy link

hastinbe commented Nov 11, 2018

I don't understand the rationale for the change to the stub. I have 4 questions:

  • Who is saying that 2.1 billion integers is not enough for the average table?
  • Where is the evidence which shows that?
  • Why is it acceptable to increase the size of indexes, memory and storage requirements without reason?
  • Why can't users who actually require bigint auto increment columns not just specify that in their migrations, instead of changing it for all tables that don't need it?

@sisve
Copy link
Contributor Author

sisve commented Nov 11, 2018

@hastinbe I agree with your all your points. However, keep in mind that the idea of using bigint was already accepted in the previous PR, but in a way I disagree with. Assuming that we still want to default to bigIncrements, then a change to the stub seems to me like the reasonable way to go, and not a application-wide flag that toggles the behavior of increments.

@hastinbe
Copy link

I agree that this solution is better than the other, but it doesn't answer the question why any change is necessary at all

@BrandonSurowiec
Copy link
Contributor

BrandonSurowiec commented Nov 11, 2018

It was probably inspired by this: https://m.signalvnoise.com/update-on-basecamp-3-being-stuck-in-read-only-as-of-nov-8-9-22am-cst-c41df1a58352

TLDR: Ruby of Rails updated to use bigInt as the default auto increment column two years ago. Basecamp never implemented the change themselves and had downtime as a result.

@mfn
Copy link
Contributor

mfn commented Nov 11, 2018

Thanks for the PR/mindset.

This is an important issue which usually discovered at later stage cycles when it becomes a burden. There's been enough "evidence" over the internet of companies gotten bitten by this.

I was leading a mid-sized MySQL->PgSQL migration last year and we already put us on the bigIncrements track and we're far away from reaching the limits.

But: being aware of this "future problem" and being not constrained by external factors and storage space not being an issue, we already decided to go with that train.

As such, I applaud this, thanks!

@hastinbe
Copy link

@BrandonSurowiec which is exactly why this change makes no sense. The rationale is based on "because rails did it" and that Basecamp ran out of IDs because they didn't update their table schemas as their data grew too large for 32-bit ints.

If we look at the original article about why Rails moved to BIGINT (http://www.mccartie.com/2016/12/05/rails-5.1.html), they also have no rationale other than to do it because there's a chance that you might become Twitter one day. So why penalize everyone who don't have these sorts of problems?

If you're growing to hundreds of millions of rows of data, you should be well aware that these sort of problems will happen and adjust accordingly. The problem was negligence of the person managing their application and database in both cases and not their framework.

This change isn't an improvement, this is a deoptimization to everyone and every table you make that doesn't need BIGINT, which is the majority of cases.

@antonkomarev
Copy link
Contributor

antonkomarev commented Nov 11, 2018

Just one small notice about id BIGINT vs INT questions: we already using unsignedBigInteger in morph columns since 5.6 #23320
And it's indirectly related to laravel/ideas#1172

@mallardduck
Copy link
Contributor

Just putting in my 2cents that this is a much more elegant solution than the current one. The original change has caused more issues than it likely solved. The only main benefit is that it solved a whole load of theoretical issues. That doesn't make up for things breaking more tho.

gomasy added a commit to gomasy/bookshelf that referenced this pull request Sep 17, 2019
* Target Laravel 5.8

* Update composer.json

* Update `RegisterController` password validation rule and associated lang file

* Update UserFactory password in line with #4794

The new password is of 8 characters, as required by #4794

* Update VerificationController.php

* add dynamo to stubs

* tweak wording

* Modify RedirectIfAuthenticated middleware to accept multiple guards

* add env variable for mysql ssl cert

* Add beanstalk queue block_for config key

This functionality was added in laravel/framework 9aa1706.

* Hint for lenient log stacks

* adjust name of configuration value

* Use same version as framework

* Use $_SERVER instead of $_ENV for phpunit.

Laravel 5.8 limits dotenv to only rely on $_SERVER and not $_ENV. See laravel/framework#27462

* change default redis configuration structure

* update client

* update config file

* [5.8] use bigIncrements by default

All new migrations will be using bigIncrements
laravel/framework#26472

* Revert "[5.8] Modify RedirectIfAuthenticated middleware to accept multiple guards"

* revert to old redis config

* add postmark token

* Add Arr and Str aliases by default

* add postmark

* update env variable stubs

* set default region

* add bucket to env example

* Use correct env name for AWS region from env.example

* comment

* comment out options

* check if extension loaded

* Ignore SQLite journals

* Prefix redis database connection by default to mitigate multiple sites on the same server potentially sharing the same queued jobs

* Use Str class instead of helper function

* Additional underscore on redis database prefix

* Additional underscore on cache prefix

* Remove underscore as cache prefixes automatically have a colon appended to them

* Update UserFactory.php

* Fix phpdoc to order by syntax convention (#5005)

Reorder the `@var` phpdoc syntax by convention, see http://docs.phpdoc.org/references/phpdoc/tags/var.html

* Update database config relating to Url addition.

* formatting

* Add ends_with validation message

* Fix type hint for case of trusting all proxies (string) (#5025)

* Add DYNAMODB_ENDPOINT to the cache config (#5034)

This adds the DYNAMODB_ENDPOINT environment variable to the
dynamodb store of the cache cofig.

Its usage is implemented in the framework as laravel/framework#28600

* Added support for new redis URL property in config/database.php (#5037)

Regarding laravel/framework#28612

* use generic default db config

* Update .gitignore (#5046)

* Move TrustProxies to highest priority - fixes maintenance mode ip whitelist if behind proxy e.g. Cloudflare (#5055)

* update deprecated pusher option (#5058)

* Using environment variable to set redis prefix (#5062)

It was the only redis setting that wasn't overridable by an environment variable. It can help if you have multiple instances using the same `APP_NAME`, e.g. a staging instance

* Remove Stripe config settings

These now ship with a dedicated config file for Cashier.

* formatting

* Update composer.lock

* Revert "[5.8] use bigIncrements by default"

This reverts commit 6c5798e.

* Update laravel/telescope
comu2e pushed a commit to comu2e/GearLab that referenced this pull request Dec 12, 2021
All new migrations will be using bigIncrements
laravel/framework#26472
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

Successfully merging this pull request may close these issues.

8 participants