Skip to content

Instantly share code, notes, and snippets.

@samcorcos
Last active August 9, 2016 06:35
Show Gist options
  • Save samcorcos/3f9f8ef9c2f0409c04636923384f7a1c to your computer and use it in GitHub Desktop.
Save samcorcos/3f9f8ef9c2f0409c04636923384f7a1c to your computer and use it in GitHub Desktop.
# priv/repo/set_subscription_renew.exs
# This script is run with:
# mix run priv/repo/set_subscription_renew.exs
alias LearnPhoenix.{Repo, User}
import Ecto.Query
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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment