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

make migration id bigserial #641

Merged
merged 4 commits into from
Mar 4, 2021
Merged

Conversation

jkthorne
Copy link
Contributor

@jkthorne jkthorne commented Mar 1, 2021

Cockrochdb uses a bigserial and this breaks with using the migrator. This is compatible with both postgresql and cockroachdb.

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm cool with this change, but one thing I'm wondering is what happens for existing apps that try to run a migration? Crystal-db will try to pull out the serial field, and cast to Int64, right? Will the upcast still work, or will that tank? 🤔

Or we say this is a breaking change, and then write up a little migration that updates the existing column....

@jwoertink
Copy link
Member

side note, ignore the ameba failures. Everything has been updating to 0.14 which seems to have some issues.

@robacarp
Copy link
Contributor

robacarp commented Mar 1, 2021

It's been a few compiler versions, but I don't think upcasting works. If it expects an Int64 and gets an Int32, it doesn't work. That makes this a breaking change, but I think it's still 🆗.

@matthewmcgarvey
Copy link
Member

I'd rather not have a breaking change here. We can create an alias alias MigrationId = Int32 | Int64 and that should work without breaking existing apps

@jwoertink
Copy link
Member

I've never used Cockroachdb, but I'm under the impression the error is more on the db side where it's defined as serial vs bigserial. If that's the case, would adding that alias make a difference? @wontruefree can you confirm which side is having the issue on this? Like, is cockroach failing because the table defines serial, and it doesn't know how to handle that, or is it that it returns In32 on the crystal side?

@jkthorne
Copy link
Contributor Author

jkthorne commented Mar 1, 2021

This is a cockroachdb issue and one that I have brought up with there team. Here is an old issue linked here.
cockroachdb/cockroach#55864

Migrating existing application is a concern for sure. I think the idea of an alias can solve the problem of older applications.

I think a concern like this eventually migrate to avram so different database adapters could handle this.

@jwoertink
Copy link
Member

Ah, so if we had the alias, and old apps used serial, and new apps used bigserial, then it would work for both? If that's the case, then let's add in that alias, and then update the return type to point to that alias. How does that sound @matthewmcgarvey ?

@stephendolan
Copy link
Member

Just tested this by:

  • Creating a new default 0.26 Lucky app via lucky init.custom my_app
  • Running ./script/setup and verifying that the migrations table id was of type integer
  • Adding a shard.override.yml with @wontruefree's fork of avram, on the master branch
  • Verifying that the content from this PR was indeed in lib/avram
  • Running lucky gen.model Post body:String and then lucky db.migrate
  • Migration ran successfully, posts table existed in the database

Copy link
Member

@matthewmcgarvey matthewmcgarvey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @wontruefree 🎉

@matthewmcgarvey matthewmcgarvey merged commit 230bdb4 into luckyframework:master Mar 4, 2021
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.

5 participants