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

Update to Ecto 3.0 #728

Merged
merged 14 commits into from Oct 17, 2018

Stricter datetime handling

  • Loading branch information...
wojtekmach committed Oct 10, 2018
commit 2e34b833d8d903220f7f6828f971f9ca1f33f923
View
@@ -27,7 +27,8 @@ config :hexpm, Hexpm.RepoBase,
priv: "priv/repo",
protector: false,
overload_alarm: false,
underload_alarm: false
underload_alarm: false,
This conversation was marked as resolved by ericmj

This comment has been minimized.

@ericmj

ericmj Oct 17, 2018

Member

Do we still have the protector and alarm options when not using sbroker?

This comment has been minimized.

This comment has been minimized.

@wojtekmach

wojtekmach Oct 17, 2018

Member

You're right, it was a sbroker option.

migration_timestamps: [type: :utc_datetime_usec]
config :sasl, sasl_error_logger: false
@@ -11,7 +11,7 @@ defmodule Hexpm.Accounts.Email do
field :public, :boolean, default: false
field :gravatar, :boolean, default: false
field :verification_key, :string
field :verification_expiry, :utc_datetime
field :verification_expiry, :utc_datetime_usec
belongs_to :user, User
@@ -11,12 +11,12 @@ defmodule Hexpm.Accounts.Key do
field :secret_first, :string
field :secret_second, :string
field :public, :boolean, default: true
field :revoke_at, :utc_datetime
field :revoked_at, :utc_datetime
field :revoke_at, :utc_datetime_usec
field :revoked_at, :utc_datetime_usec
timestamps()
embeds_one :last_use, Use, on_replace: :delete do
field :used_at, :utc_datetime
field :used_at, :utc_datetime_usec
field :user_agent, :string
field :ip, :string
end
@@ -7,6 +7,6 @@ defmodule Hexpm.Repository.Download do
belongs_to :release, Release
field :downloads, :integer
field :day, :date
field :updated_at, :utc_datetime, virtual: true
field :updated_at, :utc_datetime_usec, virtual: true
end
end
@@ -7,7 +7,7 @@ defmodule Hexpm.Repository.Package do
schema "packages" do
field :name, :string
field :docs_updated_at, :utc_datetime
field :docs_updated_at, :utc_datetime_usec
field :latest_version, Hexpm.Version, virtual: true
timestamps()
View
@@ -19,7 +19,7 @@ defmodule Hexpm.Web do
def schema() do
quote do
use Ecto.Schema
@timestamps_opts [type: :utc_datetime, usec: true]
@timestamps_opts [type: :utc_datetime_usec]
import Ecto
import Ecto.Changeset
@@ -0,0 +1,25 @@
defmodule Hexpm.RepoBase.Migrations.UpdateTimestampFields do
use Ecto.Migration
defp fixup(table, columns) do
alter table(table) do
for column <- columns do
modify(column, :utc_datetime_usec)
This conversation was marked as resolved by ericmj

This comment has been minimized.

@ericmj

ericmj Oct 17, 2018

Member

What postgres types are we changing between here?

This comment has been minimized.

@wojtekmach

wojtekmach Oct 17, 2018

Member

We're changing from TIMESTAMP(0) to TIMESTAMP

end
end
end
def change do
fixup(:emails, [:verification_expiry])
fixup(:packages, [:docs_updated_at])
fixup(:organization_users, [:inserted_at, :updated_at])
fixup(:organizations, [:inserted_at, :updated_at])
fixup(:password_resets, [:inserted_at])
fixup(:sessions, [:inserted_at, :updated_at])
end
end
@@ -322,16 +322,15 @@ defmodule Hexpm.Web.API.ReleaseControllerTest do
package: package,
release: release
} do
Ecto.Changeset.change(
package,
inserted_at: NaiveDateTime.add(NaiveDateTime.utc_now(), -36000, :second)
)
datetime =
NaiveDateTime.utc_now()
|> NaiveDateTime.add(-36000, :second)
|> DateTime.from_naive!("Etc/UTC")
Ecto.Changeset.change(package, inserted_at: datetime)
|> Hexpm.Repo.update!()
Ecto.Changeset.change(
release,
inserted_at: NaiveDateTime.add(NaiveDateTime.utc_now(), -36000, :second)
)
Ecto.Changeset.change(release, inserted_at: datetime)
|> Hexpm.Repo.update!()
meta = %{name: package.name, version: "0.0.1", description: "description"}
@@ -348,10 +347,10 @@ defmodule Hexpm.Web.API.ReleaseControllerTest do
package: package,
release: release
} do
Ecto.Changeset.change(package, inserted_at: %{NaiveDateTime.utc_now() | year: 2000})
Ecto.Changeset.change(package, inserted_at: %{DateTime.utc_now() | year: 2000})
|> Hexpm.Repo.update!()
Ecto.Changeset.change(release, inserted_at: %{NaiveDateTime.utc_now() | year: 2000})
Ecto.Changeset.change(release, inserted_at: %{DateTime.utc_now() | year: 2000})
|> Hexpm.Repo.update!()
meta = %{name: package.name, version: "0.0.1", description: "description"}
@@ -665,7 +664,7 @@ defmodule Hexpm.Web.API.ReleaseControllerTest do
:release,
package: package,
version: "0.0.1",
inserted_at: %{NaiveDateTime.utc_now() | year: 2000}
inserted_at: %{DateTime.utc_now() | year: 2000}
)
insert(:organization_user, organization: organization, user: user)
@@ -682,10 +681,10 @@ defmodule Hexpm.Web.API.ReleaseControllerTest do
describe "DELETE /api/packages/:name/releases/:version" do
test "delete release validates release age", %{user: user, package: package, release: release} do
Ecto.Changeset.change(package, inserted_at: %{NaiveDateTime.utc_now() | year: 2000})
Ecto.Changeset.change(package, inserted_at: %{DateTime.utc_now() | year: 2000})
|> Hexpm.Repo.update!()
Ecto.Changeset.change(release, inserted_at: %{NaiveDateTime.utc_now() | year: 2000})
Ecto.Changeset.change(release, inserted_at: %{DateTime.utc_now() | year: 2000})
|> Hexpm.Repo.update!()
conn =
@@ -700,7 +699,7 @@ defmodule Hexpm.Web.API.ReleaseControllerTest do
end
test "delete release", %{user: user, package: package, release: release} do
Ecto.Changeset.change(release, inserted_at: %{NaiveDateTime.utc_now() | year: 2030})
Ecto.Changeset.change(release, inserted_at: %{DateTime.utc_now() | year: 2030})
|> Hexpm.Repo.update!()
build_conn()
@@ -796,7 +795,7 @@ defmodule Hexpm.Web.API.ReleaseControllerTest do
:release,
package: package,
version: "0.0.1",
inserted_at: %{NaiveDateTime.utc_now() | year: 2000}
inserted_at: %{DateTime.utc_now() | year: 2000}
)
insert(:organization_user, organization: organization, user: user)
ProTip! Use n and p to navigate between commits in a pull request.