changed
CHANGELOG.md
|
@@ -1,3 1,9 @@
|
1
|
## [0.14.1] - 2024-08-20
|
2
|
|
3
|
### Added
|
4
|
|
5
|
* Add `:order_by` option to `Carbonite.Query.changes/2` to either disable default ordering or specify the order.
|
6
|
|
1
7
|
## [0.14.0] - 2024-07-25
|
2
8
|
|
3
9
|
**New migration patches:** 10
|
changed
README.md
|
@@ -93,7 93,7 @@ Due to its use of [`pg_current_xact_id`](https://www.postgresql.org/docs/13/func
|
93
93
|
# mix.exs
|
94
94
|
def deps do
|
95
95
|
[
|
96
|
- {:carbonite, "~> 0.14.0"}
|
96
|
{:carbonite, "~> 0.14.1"}
|
97
97
|
]
|
98
98
|
end
|
99
99
|
```
|
|
@@ -120,7 120,7 @@ defmodule MyApp.Repo.Migrations.InstallCarbonite do
|
120
120
|
use Ecto.Migration
|
121
121
|
|
122
122
|
def up do
|
123
|
- Carbonite.Migrations.up(1..9)
|
123
|
Carbonite.Migrations.up(1..10)
|
124
124
|
|
125
125
|
# For each table that you want to capture changes of, you need to install the trigger.
|
126
126
|
Carbonite.Migrations.create_trigger(:rabbits)
|
|
@@ -140,7 140,7 @@ defmodule MyApp.Repo.Migrations.InstallCarbonite do
|
140
140
|
Carbonite.Migrations.drop_trigger(:rabbits)
|
141
141
|
|
142
142
|
# Drop the Carbonite tables.
|
143
|
- Carbonite.Migrations.down(9..1)
|
143
|
Carbonite.Migrations.down(10..1)
|
144
144
|
end
|
145
145
|
end
|
146
146
|
```
|
changed
hex_metadata.config
|
@@ -1,6 1,6 @@
|
1
1
|
{<<"links">>,[{<<"github">>,<<"https://github.com/bitcrowd/carbonite">>}]}.
|
2
2
|
{<<"name">>,<<"carbonite">>}.
|
3
|
- {<<"version">>,<<"0.14.0">>}.
|
3
|
{<<"version">>,<<"0.14.1">>}.
|
4
4
|
{<<"description">>,<<"Audit trails for Elixir/PostgreSQL based on triggers">>}.
|
5
5
|
{<<"elixir">>,<<"~> 1.11">>}.
|
6
6
|
{<<"app">>,<<"carbonite">>}.
|
changed
lib/carbonite/query.ex
|
@@ -16,6 16,7 @@ defmodule Carbonite.Query do
|
16
16
|
|
17
17
|
@type prefix_option :: {:carbonite_prefix, prefix()}
|
18
18
|
@type preload_option :: {:preload, boolean()}
|
19
|
@type order_by_option :: {:order_by, false | nil | term()}
|
19
20
|
|
20
21
|
@type transactions_option :: prefix_option() | preload_option()
|
21
22
|
|
|
@@ -181,7 182,8 @@ defmodule Carbonite.Query do
|
181
182
|
|
182
183
|
@default_table_prefix "public"
|
183
184
|
|
184
|
- @type changes_option :: prefix_option() | preload_option() | {:table_prefix, prefix()}
|
185
|
@type changes_option ::
|
186
|
prefix_option() | preload_option() | order_by_option() | {:table_prefix, prefix()}
|
185
187
|
|
186
188
|
@doc """
|
187
189
|
Returns an `t:Ecto.Query.t/0` that can be used to select changes for a single record.
|
|
@@ -201,6 203,7 @@ defmodule Carbonite.Query do
|
201
203
|
* `carbonite_prefix` defines the audit trail's schema, defaults to `"carbonite_default"`
|
202
204
|
* `table_prefix` allows to override the table prefix, defaults to schema prefix of the record
|
203
205
|
* `preload` can be used to preload the transaction
|
206
|
* `order_by` allows to override the ordering, defaults to `{:asc, :id}`
|
204
207
|
"""
|
205
208
|
@doc since: "0.2.0"
|
206
209
|
@spec changes(record :: Ecto.Schema.t()) :: Ecto.Query.t()
|
|
@@ -223,7 226,7 @@ defmodule Carbonite.Query do
|
223
226
|
|> where([c], c.table_name == ^table_name)
|
224
227
|
|> where([c], c.table_pk == ^table_pk)
|
225
228
|
|> maybe_preload(opts, :transaction, from_with_prefix(Transaction, opts))
|
226
|
- |> order_by({:asc, :id})
|
229
|
|> maybe_order_by(opts)
|
227
230
|
end
|
228
231
|
|
229
232
|
defp maybe_apply(queryable, opts, key, default, fun) do
|
|
@@ -234,6 237,16 @@ defmodule Carbonite.Query do
|
234
237
|
end
|
235
238
|
end
|
236
239
|
|
240
|
defp maybe_order_by(queryable, opts) do
|
241
|
case Keyword.get(opts, :order_by, {:asc, :id}) do
|
242
|
order_by when order_by in [false, nil] ->
|
243
|
queryable
|
244
|
|
245
|
value ->
|
246
|
order_by(queryable, ^value)
|
247
|
end
|
248
|
end
|
249
|
|
237
250
|
defp maybe_preload(queryable, opts, association, preload_query) do
|
238
251
|
case Keyword.get(opts, :preload, false) do
|
239
252
|
preload when preload in [false, nil] ->
|
changed
mix.exs
|
@@ -3,7 3,7 @@
|
3
3
|
defmodule Carbonite.MixProject do
|
4
4
|
use Mix.Project
|
5
5
|
|
6
|
- @version "0.14.0"
|
6
|
@version "0.14.1"
|
7
7
|
|
8
8
|
def project do
|
9
9
|
[
|