Last active
August 9, 2016 06:24
-
-
Save samcorcos/f01ab61149bee1f81d06ca537368a3e3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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