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

Fix add column example #196

Open
paulcsmith opened this issue Dec 2, 2019 · 0 comments

Comments

@paulcsmith
Copy link
Member

@paulcsmith paulcsmith commented Dec 2, 2019

Gitter: https://gitter.im/luckyframework/Lobby?at=5de4589a46397c721c6d10a2

def migrate
  alter table_for(User) do
    # Add nullable column first
    add otp_code : String?
  end

  # Then add values to it
  UserQuery.new.each do |user|
    User::SaveOperation.udpate!(user, otp_code: CodeGenerator.generate)
  end

  # Then make it non-nullable
  make_required :otp_code
end

that code example has at least two mistakes, one is the udpate, the other that make_required needs the table name as argument as well
from https://luckyframework.org/guides/database/migrations#using-fill_existing_with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.