Skip to content

Instantly share code, notes, and snippets.

@samcorcos
Last active August 9, 2016 06:24
Show Gist options
  • Save samcorcos/f01ab61149bee1f81d06ca537368a3e3 to your computer and use it in GitHub Desktop.
Save samcorcos/f01ab61149bee1f81d06ca537368a3e3 to your computer and use it in GitHub Desktop.
# priv/repo/migrations/20160809055905_set_subscription_renew_for_users.exs
defmodule LearnPhoenix.Repo.Migrations.SetSubscriptionRenewForUsers do
use Ecto.Migration
alias LearnPhoenix.{Repo, User}
import Ecto.Query
def up do
set_subscription_renew = from(u in User, update: [set: [subscription_renew: true]])
Repo.update_all(set_subscription_renew, [])
now = Ecto.DateTime.utc()
users = from(u in User, where: u.subscription_expiration < ^now)
Repo.update_all(users, set: [subscription_renew: false])
end
def down do
set_subscription_renew = from(u in User, update: [set: [subscription_renew: nil]])
Repo.update_all(set_subscription_renew, [])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment