Skip to content

Commit

Permalink
Upgrade elixir and deps (#496)
Browse files Browse the repository at this point in the history
* upgrade elixir

* upgrade elixir

* Fix upgrade to ecto

* fix jose deps

* replace ecto atom to enum

* Fix build

* fix migrations

* update deps

* Fix the search integration with the frontend

* use utc for non timestamp fields

* format the code

* use naive date time for date time
  • Loading branch information
pkrawat1 authored Aug 8, 2022
1 parent 54d264f commit 8eb0c67
Show file tree
Hide file tree
Showing 66 changed files with 406 additions and 414 deletions.
4 changes: 3 additions & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
elixir 1.7.2
elixir 1.13.4-otp-25
nodejs 8.10.0
erlang 25.0.3
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ after_script:
- bash .scripts/inch_report.sh
matrix:
include:
- elixir: 1.7.2
- elixir: 1.13.4
script:
- mix coveralls.json --umbrella
addons:
Expand Down
2 changes: 1 addition & 1 deletion apps/admin_app/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ config :admin_app, AdminAppWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "o7U+x3aM3mqN1vY+PGIbxEN+QBeMP7rwgCpyrbYfEUkAY6I12cxKvwEt/zJeGjgR",
render_errors: [view: AdminAppWeb.ErrorView, accepts: ~w(html json json-api)],
pubsub: [name: AdminApp.PubSub, adapter: Phoenix.PubSub.PG2],
pubsub_server: AdminApp.PubSub,
token_maximum_age: System.get_env("TOKEN_MAXIMUM_AGE"),
sendgrid_sender_mail: System.get_env("SENDGRID_SENDER_EMAIL"),
password_reset_salt: System.get_env("PASSWORD_RESET_SALT"),
Expand Down
3 changes: 2 additions & 1 deletion apps/admin_app/lib/admin_app/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ defmodule AdminApp.Application do
# Define workers and child supervisors to be supervised
children = [
# Start the endpoint when the application starts
supervisor(AdminAppWeb.Endpoint, [])
supervisor(AdminAppWeb.Endpoint, []),
{Phoenix.PubSub, [name: AdminApp.PubSub, adapter: Phoenix.PubSub.PG2]}
# Start your own worker by calling: AdminApp.Worker.start_link(arg1, arg2, arg3)
# worker(AdminApp.Worker, [arg1, arg2, arg3]),
]
Expand Down
4 changes: 2 additions & 2 deletions apps/admin_app/lib/admin_app/etsy_importer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ defmodule Avia.Etsy.Importer do

defp timestamps() do
%{
inserted_at: Ecto.DateTime.utc(),
updated_at: Ecto.DateTime.utc()
inserted_at: NaiveDateTime.utc_now(),
updated_at: NaiveDateTime.utc_now()
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</div>
<% end %>
<div class="main" >
<%= Map.get(assigns, :inner_layout) || render @view_module, @view_template, assigns %>
<%= Map.get(assigns, :inner_layout) || @inner_content %>
</div>
</main>
4 changes: 1 addition & 3 deletions apps/admin_app/lib/admin_app_web/views/input_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ defmodule AdminAppWeb.InputHelpers do

wrapper_opts = [
class:
"form-group form-group-default input-group cb-group #{validate_required} #{
state_class(form, field)
}"
"form-group form-group-default input-group cb-group #{validate_required} #{state_class(form, field)}"
]

type = Form.input_type(form, field)
Expand Down
4 changes: 1 addition & 3 deletions apps/admin_app/lib/admin_app_web/views/product_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ defmodule AdminAppWeb.ProductView do

def make_search_query_string(conn, column, expression, type, term) do
query =
"&rummage[search][#{column}][search_expr]=#{expression}&rummage[search][#{column}][search_type]=#{
type
}&rummage[search][#{column}][search_term]=#{term}"
"&rummage[search][#{column}][search_expr]=#{expression}&rummage[search][#{column}][search_type]=#{type}&rummage[search][#{column}][search_term]=#{term}"

conn_query =
load_query_string(conn, ["rummage", "sort"], ["rummage", "search"])
Expand Down
14 changes: 7 additions & 7 deletions apps/admin_app/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule AdminApp.Mixfile do
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.7.2",
elixir: "~> 1.13.4",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
Expand All @@ -36,18 +36,18 @@ defmodule AdminApp.Mixfile do
# Type `mix help deps` for examples and options.
defp deps do
[
{:phoenix, "~> 1.3.0"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix, "~> 1.5.0"},
{:phoenix_pubsub, "~> 2.0"},
{:phoenix_html, "~> 2.10"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:phoenix_ecto, "~> 3.0"},
{:phoenix_ecto, "~> 4.4"},
{:gettext, "~> 0.11"},
{:csv, "~> 2.0.0"},
{:elixlsx, "~> 0.1.1"},
{:cowboy, "~> 1.0"},
{:plug_cowboy, "~> 2.5"},
{:snitch_core, "~> 0.0.1", in_umbrella: true},
{:guardian, "~> 1.0"},
{:params, "~> 2.0"},
{:params, "~> 2.2"},
{:yaml_elixir, "~> 2.1.0"},
# email
{:swoosh, "~> 0.15"},
Expand All @@ -59,7 +59,7 @@ defmodule AdminApp.Mixfile do

# import from store
{:oauther, "~> 1.1"},
{:honeydew, "~> 1.2.6"}
{:honeydew, "~> 1.5"}
]
end
end
10 changes: 0 additions & 10 deletions apps/admin_app/node_modules/.yarn-integrity

This file was deleted.

2 changes: 1 addition & 1 deletion apps/help/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Help.Mixfile do
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.5",
elixir: "~> 1.13.4",
start_permanent: Mix.env() == :prod,
deps: deps()
]
Expand Down
2 changes: 1 addition & 1 deletion apps/snitch_api/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ config :snitch_api, SnitchApiWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "VAvkjDkSJ/5nLB4aI+77rZ/PyR3foxuD6u1p1X01M3hpc0MJrRDwRNZ0/ERHfcUb",
render_errors: [view: SnitchApiWeb.ErrorView, accepts: ~w(json)],
pubsub: [name: SnitchApi.PubSub, adapter: Phoenix.PubSub.PG2]
pubsub_server: SnitchApi.PubSub

# Configures Elixir's Logger
config :logger, :console,
Expand Down
3 changes: 2 additions & 1 deletion apps/snitch_api/lib/snitch_api/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ defmodule SnitchApi.Application do
# Define workers and child supervisors to be supervised
children = [
# Start the endpoint when the application starts
supervisor(SnitchApiWeb.Endpoint, [])
supervisor(SnitchApiWeb.Endpoint, []),
{Phoenix.PubSub, [name: SnitchApi.PubSub, adapter: Phoenix.PubSub.PG2]}
# Start your own worker by calling: SnitchApi.Worker.start_link(arg1, arg2, arg3)
# worker(SnitchApi.Worker, [arg1, arg2, arg3]),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ defmodule SnitchApiWeb.HostedPaymentController do

defp generate_payubiz_hash(params) do
hash_string =
"#{params[:key]}|#{params[:txnid]}|#{params[:amount]}|#{params[:productinfo]}|#{
params[:firstname]
}|#{params[:email]}#{String.duplicate("|", 11)}#{params[:salt]}"
"#{params[:key]}|#{params[:txnid]}|#{params[:amount]}|#{params[:productinfo]}|#{params[:firstname]}|#{params[:email]}#{String.duplicate("|", 11)}#{params[:salt]}"

Base.encode16(:crypto.hash(:sha512, hash_string), case: :lower)
end
Expand Down
8 changes: 4 additions & 4 deletions apps/snitch_api/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule SnitchApi.Mixfile do
config_path: "../../config/config.exs",
deps_path: "../../deps",
lockfile: "../../mix.lock",
elixir: "~> 1.7.2",
elixir: "~> 1.13.4",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
Expand All @@ -36,10 +36,10 @@ defmodule SnitchApi.Mixfile do
# Type `mix help deps` for examples and options.
defp deps do
[
{:phoenix, "~> 1.3.0"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix, "~> 1.5.0"},
{:phoenix_pubsub, "~> 2.0"},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:plug_cowboy, "~> 2.5"},
{:snitch_core, "~> 0.0.1", in_umbrella: true},
{:plug, "~> 1.0"},
{:corsica, "~> 1.0"},
Expand Down
2 changes: 2 additions & 0 deletions apps/snitch_core/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ config :snitch_core, Snitch.Tools.ElasticsearchCluster,
}
}

config :ex_cldr, default_backend: Snitch.Tools.Cldr

import_config "#{Mix.env()}.exs"
3 changes: 2 additions & 1 deletion apps/snitch_core/config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ config :snitch_core, Snitch.Repo,
password: "postgres",
database: "snitch_dev",
hostname: System.get_env("DB_HOST"),
pool_size: 10
pool_size: 10,
show_sensitive_data_on_connection_error: true

config :snitch_core, :defaults_module, Snitch.Tools.Defaults
config :arc, storage: Arc.Storage.Local
Expand Down
2 changes: 1 addition & 1 deletion apps/snitch_core/lib/core/data/model/product.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ defmodule Snitch.Data.Model.Product do
|> Repo.all()

Product
|> join(:left, [p], v in Variation, v.child_product_id == p.id)
|> join(:left, [p], v in Variation, on: v.child_product_id == p.id)
|> where(
[p, v],
p.state == "active" and p.deleted_at == ^0 and p.id not in ^parent_product_ids
Expand Down
4 changes: 2 additions & 2 deletions apps/snitch_core/lib/core/data/model/role.ex
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ defmodule Snitch.Data.Model.Role do
[
permission_id: permission,
role_id: role.id,
inserted_at: DateTime.utc_now(),
updated_at: DateTime.utc_now()
inserted_at: NaiveDateTime.local_now(),
updated_at: NaiveDateTime.local_now()
]
end)
end
Expand Down
2 changes: 1 addition & 1 deletion apps/snitch_core/lib/core/data/schema/payment/payment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Snitch.Data.Schema.Payment do

schema "snitch_payments" do
field(:slug, :string)
field(:payment_type, :string, size: 3)
field(:payment_type, :string)
field(:amount, Money.Ecto.Composite.Type, default: Money.new(0, :USD))
field(:state, :string, default: "pending")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ defmodule Snitch.Data.Schema.PaymentMethod do
use Snitch.Data.Schema

alias Snitch.Data.Schema.Payment
alias SnitchPayments.Gateway.{PayuBiz, Stripe, RazorPay}
alias SnitchPayments.Payment.CashOnDelivery

@typedoc """
A struct which represents PaymentMethod.
Expand All @@ -32,11 +34,11 @@ defmodule Snitch.Data.Schema.PaymentMethod do

schema "snitch_payment_methods" do
field(:name, :string)
field(:code, :string, size: 3)
field(:code, :string)
field(:active?, :boolean, default: true)

field(:live_mode?, :boolean, default: false)
field(:provider, Ecto.Atom)
field(:provider, Ecto.Enum, values: [PayuBiz, Stripe, RazorPay, CashOnDelivery])
field(:preferences, :map)
field(:description, :string)

Expand Down
2 changes: 1 addition & 1 deletion apps/snitch_core/lib/core/data/schema/product.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Snitch.Data.Schema.Product do
@type t :: %__MODULE__{}

schema "snitch_products" do
field(:name, :string, null: false, default: "")
field(:name, :string, default: "")
field(:description, :string)
field(:available_on, :utc_datetime)
field(:deleted_at, UnixTimestamp, default: 0)
Expand Down
2 changes: 1 addition & 1 deletion apps/snitch_core/lib/core/data/schema/product_brand.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Snitch.Data.Schema.ProductBrand do
@type t :: %__MODULE__{}

schema "snitch_product_brands" do
field(:name, :string, null: false)
field(:name, :string)
field(:tenant, :string, virtual: true)
timestamps()

Expand Down
2 changes: 1 addition & 1 deletion apps/snitch_core/lib/core/data/schema/product_property.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Snitch.Data.Schema.ProductProperty do
schema "snitch_product_properties" do
belongs_to(:product, Product)
belongs_to(:property, Property)
field(:value, :string, null: false)
field(:value, :string)
timestamps()
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule Snitch.Data.Schema.Promotion do
field(:code, :string)
field(:name, :string)
field(:description, :string)
field(:starts_at, :utc_datetime, default: DateTime.utc_now())
field(:starts_at, :utc_datetime, default: DateTime.truncate(DateTime.utc_now(), :second))
field(:expires_at, :utc_datetime)
field(:usage_limit, :integer, default: 0)
field(:current_usage_count, :integer, default: 0)
Expand Down
6 changes: 3 additions & 3 deletions apps/snitch_core/lib/core/data/schema/rating/rating_option.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ defmodule Snitch.Data.Schema.RatingOption do
@type t :: %__MODULE__{}

schema "snitch_rating_options" do
field(:code, :string, null: false)
field(:value, :integer, null: false)
field(:position, :integer, null: false)
field(:code, :string)
field(:value, :integer)
field(:position, :integer)

belongs_to(:rating, Rating)

Expand Down
6 changes: 1 addition & 5 deletions apps/snitch_core/lib/core/data/schema/shipping_method.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ defmodule Snitch.Data.Schema.ShippingMethod do
The `zones` must be `Snitch.Data.Schema.Zone.t` structs.
The `categories` must be `Snitch.Data.Schema.ShippingCategory.t` structs.
The following fields must be present in `params`: `[#{
@create_fields
|> Enum.map(fn x -> ":#{x}" end)
|> Enum.intersperse(", ")
}]`
The following fields must be present in `params`: `[#{@create_fields |> Enum.map(fn x -> ":#{x}" end) |> Enum.intersperse(", ")}]`
"""
@spec create_changeset(t, map, [Zone.t()], [ShippingCategory.t()]) :: Ecto.Changeset.t()
def create_changeset(%__MODULE__{} = shipping_method, params, zones, categories) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Snitch.Data.Schema.ShippingRuleIdentifier do
@type t :: %__MODULE__{}

schema "snitch_shipping_rule_identifiers" do
field(:code, Ecto.Atom)
field(:code, Ecto.Enum, values: [:fso, :fsoa, :fsrp, :ofr])
field(:description, :string)

timestamps()
Expand Down
4 changes: 2 additions & 2 deletions apps/snitch_core/lib/core/data/schema/taxanomy/taxon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ defmodule Snitch.Data.Schema.Taxon do
timestamps()
end

@cast_fields ~w(name parent_id taxonomy_id lft rgt)
@update_fields ~w(name)
@cast_fields ~w(name parent_id taxonomy_id lft rgt)a
@update_fields ~w(name)a

def changeset(taxon, params) do
taxon
Expand Down
2 changes: 1 addition & 1 deletion apps/snitch_core/lib/core/data/schema/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ defmodule Snitch.Data.Schema.User do
def delete_changeset(user, _params \\ %{}) do
params = %{
state: :deleted,
deleted_at: NaiveDateTime.utc_now()
deleted_at: NaiveDateTime.local_now()
}

user
Expand Down
5 changes: 2 additions & 3 deletions apps/snitch_core/lib/core/data/schema/variant.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ defmodule Snitch.Data.Schema.Variant do

use Snitch.Data.Schema

alias Money.Ecto.Composite.Type, as: MoneyType
alias Snitch.Data.Schema.{Image, Product, ShippingCategory, StockItem}

@type t :: %__MODULE__{}
Expand All @@ -16,8 +15,8 @@ defmodule Snitch.Data.Schema.Variant do
field(:height, :decimal, default: Decimal.new(0))
field(:width, :decimal, default: Decimal.new(0))
field(:depth, :decimal, default: Decimal.new(0))
field(:selling_price, MoneyType)
field(:cost_price, MoneyType)
field(:selling_price, Money.Ecto.Composite.Type)
field(:cost_price, Money.Ecto.Composite.Type)
field(:position, :integer)
field(:track_inventory, :boolean, default: true)
field(:discontinue_on, :utc_datetime)
Expand Down
1 change: 1 addition & 0 deletions apps/snitch_core/lib/core/domain/order/default_machine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ defmodule Snitch.Domain.Order.DefaultMachine do
modules/functions that perform some logic based on the state need to be
generated or configured at compile-time as well.
"""

# TODO: How to attach the additional info like ability, etc with the states?
# TODO: make the order state machine a behaviour to simplify things.

Expand Down
2 changes: 1 addition & 1 deletion apps/snitch_core/lib/core/repo.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
defmodule Snitch.Repo do
use Ecto.Repo, otp_app: :snitch_core
use Ecto.Repo, otp_app: :snitch_core, adapter: Ecto.Adapters.Postgres
end
6 changes: 6 additions & 0 deletions apps/snitch_core/lib/core/tools/cldr.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
defmodule Snitch.Tools.Cldr do
use Cldr,
locales: ["en"],
default_locale: "en",
providers: [Cldr.Number, Money]
end
Loading

0 comments on commit 8eb0c67

Please sign in to comment.