Note That money_sql
is supported on Elixir 1.11 and later only.
This is the changelog for Money_SQL v1.11.0 released on January 249h, 2023.
- When dumping a
Money.Ecto.Composite.Type
, detect ifdump/3
is being called byEcto.Type.embedded_dump/2
. If it is, then return a map that can be serialized to JSON. If it isn't (most cases) then return the tuple to be serialized to Postgres. See papertrail issue.
This is the changelog for Money_SQL v1.10.2 released on December 13th, 2023.
-
Don't propagate some Ecto schema fields in
Money.Ecto.Composite.Type.init/2
. This change deletes additionalEcto.Schema.field/3
options so they don't get loaded as format_options. Thanks to @axelclark for the PR. Closes #40. -
Fix Changelog headings and whitespace. Thanks to @c4710n for the PR. Closes #39.
This is the changelog for Money_SQL v1.10.1 released on November 3rd, 2023.
-
Fix compilation warnings on Elixir 1.16.
-
Fix migration generator for
money_with_currency
type. Thanks to @bigardone for the issue and PR. Closes #37, closes #38.
This is the changelog for Money_SQL v1.10.0 released on October 30th, 2023.
- The mix tasks that generate database function migrations (
money.gen.postgres.sum_function
,money.gen.postgres.plus_operator
andmoney.gen.postgres.min_max_functions
) need to be aware of the type of themoney_with_currency
"currency_code" element in a Postgres database. In releases ofex_money_sql
up to 1.7.1 the type waschar(3)
. In later releases is changed to the more canonicalvarchar
. In turn, the database functions need to know the type for the internal accumulator. It is possible, as illustrated in issue #36, to have generated themoney_with_currency
"currency_code" type aschar(3)
and then move to a later release ofex_money_sql
. In which case the money database function migrations would fail because they were built withvarchar
accumulators. This release will detect the underlying type of themoney_with_currency
"currency_code" element and adjust the migration accordingly. Thanks to @bigardone for the report and motivation to get this done. Closes #36.
- Adds database functions for unary negation and the operation
-
. Thanks to @zachdaniel for the PR.
This is the changelog for Money_SQL v1.9.2 released on October 1st, 2023.
- Return an error if loading invalid amounts such as
Inf
andNaN
. Thanks to @dhedlund for the report and PR. Closes #34.
This is the changelog for Money_SQL v1.9.2 released on June 17th, 2022.
Please ensure that if you are using Ecto embedded schemas that include a money
type that it is configured with the type Money.Ecto.Map.Type
, NOT Money.Ecto.Composite.Type
.
In previous releases the misconfiguration of the type worked by accident. In this release and subsequent releases you will likely see an exception like ** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for {"USD", Decimal.new("50.00")} of type Tuple
. This is most likely an indication of type misconfiguration in an embedded schema.
- Fixes dumping and loading of
Money.Ecto.Map.Type
when used in embedded schemas. Many thanks to @redrabbit for the issue and the PR. Closes #32.
This is the changelog for Money_SQL v1.9.1 released on May 12th, 2022.
- Fixes casting a map when the
"amount"
isnil
. Thanks to @treere for the report and PR. Closes #30.
This is the changelog for Money_SQL v1.9.0 released on April 28th, 2022.
- Adds
Money.Ecto.Query.API
query helpers to simplify Ecto queries involving money columns. Thanks very much to @am-kantox for the excellent suggestion and PR.
This is the changelog for Money_SQL v1.8.0 released on December 26th, 2022.
-
Adds migrations and SQL functions to support
min
andmax
aggregate functions for Postgres when using themoney_with_currency
composite data type. The new mix task ismoney.gen.postgres.min_max_functions
. -
Renames the migration task
money.gen.postgres.aggregate_functions
tomoney.gen.postgres.sum_function
to better reflect its intent. This change affects only new installations. It has no effect on pre-existing generated migrations.
This is the changelog for Money_SQL v1.7.3 released on December 18th, 2022.
- When loading money from the database with the
Money.Ecto.Map.Type
type, do not do localized parsing of the amount. The amount is always saved usingDecimal.to_string/1
and therefore is not localized. It must not be parsed with localization on loading.
This is the changelog for Money_SQL v1.7.2 released on August 27th, 2022.
- The "amount" component of
money_with_currency
in a Postgres database is nowvarchar
instead ofchar(3)
. This is both more canonical in a Postgres database and allows for the use of Digial Tokens (crypto currencies) which have a code greater than 3 characters long.
- Makes the aggregate functions parallel-safe which provides up to 100% speed improvement. Thanks to @milangupta1 for the PR.
This is the changelog for Money_SQL v1.7.1 released on July 8th, 2022.
- Fixes casting a money map when the currency is
nil
. Thanks to @frahugo for the report. Closes #24.
This is the changelog for Money_SQL v1.7.0 released on May 21st, 2022.
- Adds the module
Money.Validation
to provide Ecto Changeset validations. In particular it addsMoney.Validation.validate_money/3
which behaves exactly likeEcto.Changeset.validate_number/3
only fort:Money.t/0
types.
This is the changelog for Money_SQL v1.6.0 released on December 31st, 2021.
Note That money_sql
is now supported on Elixir 1.10 and later only.
t:Money.Ecto.Composite.Type
andt:Money.Ecto.Map.Type
now return the exception module when there is an error incast/1
. For example:
iex> Money.Ecto.Composite.Type.cast("") ==
{:error,
[
exception: Money.InvalidAmountError,
message: "Amount cannot be converted to a number: \"\""
]}
The expected exceptions are:
Money.InvalidAmountError
Money.UnknownCurrencyError
Money.ParseError
Thanks to @DaTrader for the enhancement request.
This is the changelog for Money_SQL v1.5.2 released on December 13th, 2021.
Note That money_sql
is now supported on Elixir 1.10 and later only.
- Fixes
c:Ecto.ParameterizedType.embed_as/2
callback for theEcto.ParameterizedType
behaviour. Thanks to @nseantanly for the report and the PR.
This is the changelog for Money_SQL v1.5.1 released on December 8th, 2021.
Note That money_sql
is now supported on Elixir 1.10 and later only.
-
Implements
c:Ecto.ParameterizedType.equal?/3
callback for theEcto.ParameterizedType
behaviour. Thanks to @namhoangyojee for the report and the PR. -
Adds
@impl Ecto.ParamaterizedType
to the relevant callbacks.
This is the changelog for Money_SQL v1.5.0 released on September 25th, 2021.
-
Adds a
+
operator for the Postgres type:money_with_currency
-
The name of the migration to create the
:money_with_currency
type has shortened to bemoney.gen.postgres.money_with_currency
This is the changelog for Money_SQL v1.4.5 released on June 3rd, 2021.
- Remove conditional compilation in
Money.Ecto.Composite.Type
- the type is alwaysEcto.ParameterizedType
.
This is the changelog for Money_SQL v1.4.4 released on March 18th, 2021.
- Don't use
is_struct/1
guard to support compatibility on older Elixir releases
This is the changelog for Money_SQL v1.4.3 released on February 17th, 2021.
- Don't propogate a
:default
option into thet:Money
from the schema. Fixes #14. Thanks to @emaiax.
This is the changelog for Money_SQL v1.4.2 released on February 12th, 2021.
- Dumping/loading
nil
returns{:ok, nil}
. Thanks to @morinap.
This is the changelog for Money_SQL v1.4.1 released on February 11th, 2021.
- Casting
nil
returns{:ok, nil}
. Thanks to @morinap.
This is the changelog for Money_SQL v1.4.0 released on February 10th, 2021.
-
Fix parsing error handling in
Money.Ecto.Composite.Type.cast/2
. Thanks to @NikitaAvvakumov. Closes #10. -
Fix casting localized amounts. Thanks to @olivermt. Closes #11.
- Changes
Money.Ecto.Composite.Type
andMoney.Ecto.Map.Type
to beParameterizedType
. As a result, Ecto 3.5 or later is required. This change allows configuration of format options for the:money_with_currency
to added as parameters in the Ecto schema. For the example schema:
defmodule Organization do
use Ecto.Schema
@primary_key false
schema "organizations" do
field :payroll, Money.Ecto.Composite.Type
field :tax, Money.Ecto.Composite.Type, fractional_digits: 4
field :name, :string
field :employee_count, :integer
timestamps()
end
end
The field :tax
will be instantiated as a Money.t
with :format_options
of fractional_digits: 4
.
This is the changelog for Money_SQL v1.3.1 released on September 30th, 2020.
- Fixes compatibility with both
Decimal
version1.x
and2.x
. Thanks to @doughsay and @coladarci for the report. Closes #8.
This is the changelog for Money_SQL v1.3.0 released on January 30th, 2020.
- Updates to
ex_money
version5.0
. Thanks to @morgz
This is the changelog for Money_SQL v1.2.1 released on November 3rd, 2019.
-
Fixes
Money.Ecto.Composite.Type
andMoney.Ecto.Map.Type
by ensuring theload/1
andcast/1
callbacks conform to their typespecs. Thanks to @bgracie. Closes #4 and #5. -
Fixes the migration templates for
money.gen.postgres.aggregate_functions
to usenumeric
intermediate types rather thannumeric(20,8)
. For current installations it should be enough to runmix money.gen.postgres.aggregate_functions
again followed bymix ecto.migrate
to install the corrected aggregate function.
This is the changelog for Money_SQL v1.2.0 released on November 2nd, 2019.
- Removes the precision specification from intermediate results of the
sum
aggregate function for Postgres.
- Adds
equal?/2
callbacks to theMoney.Ecto.Composite.Type
andMoney.Ecto.Map.Type
forecto_sql
version 3.2
This is the changelog for Money_SQL v1.1.0 released on August 22nd, 2019.
- Renames the migration that generator that creates the Postgres composite type to be more meaningful.
- Correctly generate and execute migrations. Fixes #1 and #2. Thanks to @davidsulc, @KungPaoChicken.
This is the changelog for Money_SQL v1.0.0 released on July 8th, 2019.
- Initial release. Extracted from ex_money