<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hataluli Randima on Medium]]></title>
        <description><![CDATA[Stories by Hataluli Randima on Medium]]></description>
        <link>https://medium.com/@hataluli.randima?source=rss-fee3829a311------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*OUaxR9_dh7w9D3b3</url>
            <title>Stories by Hataluli Randima on Medium</title>
            <link>https://medium.com/@hataluli.randima?source=rss-fee3829a311------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 00:41:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hataluli.randima/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exporting Large CSVs from Phoenix Without Exhausting Memory or Your Database Pool]]></title>
            <link>https://medium.com/@hataluli.randima/exporting-large-csvs-from-phoenix-without-exhausting-memory-or-your-database-pool-af74a263f610?source=rss-fee3829a311------2</link>
            <guid isPermaLink="false">https://medium.com/p/af74a263f610</guid>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[csv]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Hataluli Randima]]></dc:creator>
            <pubDate>Sat, 07 Nov 2026 07:35:30 GMT</pubDate>
            <atom:updated>2026-11-07T07:35:30.604Z</atom:updated>
            <content:encoded><![CDATA[<p>Almost every business application eventually gets a “Download as CSV” button. It works fine with a few hundred rows. Then the table grows to millions of rows, someone starts an export over a slow connection, and the whole app gets slower for everyone.</p><p>I’ve just released <a href="https://hex.pm/packages/beam_export"><strong>BeamExport</strong></a><strong> 0.1.0</strong>, an Elixir library for exactly this problem. This post walks through why the common approaches fail, the idea BeamExport is built on, and the failure cases that took most of the work.</p><h3>Approach 1: load everything</h3><p>The simplest version loads every row, builds the CSV in memory and sends it:</p><pre># Loads the entire dataset into the process heap<br>Repo.all(query) |&gt; Enum.map(&amp;format_row/1) |&gt; CSV.encode() |&gt; send_download(...)</pre><p>Memory grows with the size of the export. A few hundred thousand rows can mean hundreds of megabytes for a single request, plus garbage-collection pressure for everything else running on the node. A few concurrent exports can take the node down.</p><h3>Approach 2: stream straight to the client</h3><p>The usual fix is to stream. In Ecto, Repo.stream/2 reads rows through a database cursor, and a cursor must live inside a transaction:</p><pre># Holds a pool connection for as long as the slowest client takes<br>Repo.transaction(fn -&gt;<br>  query |&gt; Repo.stream() |&gt; NimbleCSV.dump_to_stream() |&gt; Enum.into(conn)<br>end, timeout: :infinity)</pre><p>Memory is now bounded, but there’s a new problem: <strong>the database connection is held for the entire download</strong>. The server can only send data as fast as the client reads it, so a client on a slow mobile connection keeps a connection from your pool checked out for minutes. Pools are small (often 10 connections), so a handful of slow downloads can starve the rest of the application. On PostgreSQL, long-running transactions also hold back vacuum.</p><h3>The idea: stage the export on disk</h3><p>The database is fast, and the network to the client is the slow part. So separate them:</p><pre>STAGE 1  database cursor ──&gt; CSV chunks ──&gt; private temp file      (holds 1 DB connection)<br>                                                │<br>         ── transaction commits, connection returns to the pool ──<br>                                                │<br>STAGE 2  HTTP client  &lt;────── send_file ─────── temp file          (no DB connection)<br>                                                │<br>         ── temp file deleted when the request process exits ──</pre><p>Stage 1 reads the rows at database speed and writes them to a temporary file in bounded chunks. The transaction commits and the connection goes back to the pool. Stage 2 serves the file with sendfile, however long the client takes, without touching the database.</p><p>The trade-off is that the response only starts once the file is written. For most exports that takes seconds. For very large ones, generate the file in a background job instead.</p><h3>Using BeamExport</h3><p>Add the dependency:</p><pre>def deps do<br>  [<br>    {:beam_export, &quot;~&gt; 0.1.0&quot;}<br>    # plus :ecto / :plug if you export from Ecto or serve downloads (Phoenix already has both)<br>  ]<br>end</pre><p>A staged download from a Phoenix controller:</p><pre>def export(conn, _params) do<br>  query = from(u in User, order_by: u.id)</pre><pre>  BeamExport.Plug.send_staged_export(conn, &quot;users.csv&quot;, {Repo, query},<br>    headers: [&quot;ID&quot;, &quot;Name&quot;, &quot;Email&quot;],<br>    mapper: fn user -&gt; [user.id, user.name, user.email] end<br>  )<br>end</pre><p>Writing a file from a background job:</p><pre>{:ok, %{rows: rows, bytes: bytes}} =<br>  BeamExport.to_file({Repo, query}, &quot;/var/app/exports/users.csv&quot;,<br>    headers: [&quot;ID&quot;, &quot;Name&quot;, &quot;Email&quot;],<br>    mapper: fn user -&gt; [user.id, user.name, user.email] end<br>  )</pre><p>A path ending in .gz gives you gzip compression on the fly. There&#39;s also to_stream/2 (a lazy stream of CSV chunks) and to_iodata/2 (for small exports, such as email attachments).</p><h3>The hard part: failing loudly</h3><p>Streaming rows into a file is the easy part. Most of the work went into the cases where things go wrong, because the worst outcome for an export isn’t an error. It’s an incomplete file that looks complete. Someone opens it, sees 40,000 rows instead of 50,000, and makes a decision based on it.</p><p>BeamExport treats that as the one thing it must never do:</p><ul><li><strong>Stalled consumers and databases.</strong> If whatever consumes a stream stops asking for data, or the database stops answering, the export fails with a BeamExport.TimeoutError (its message says the export is incomplete) instead of quietly ending early.</li><li><strong>Failed commits.</strong> Rows are only reported as done after the transaction actually commits.</li><li><strong>Disk full, reported late.</strong> Buffered file writes often report errors only when the file is <em>closed</em>, not when you write. Ignoring the return value of close is a classic way to produce truncated files. BeamExport checks it, and syncs the data to disk before an atomic rename, so a reader never sees a partial file.</li><li><strong>Cut-off downloads.</strong> If a chunked download fails mid-way, the response ends without its final chunk, so the HTTP client knows the transfer is incomplete rather than saving a short file.</li><li><strong>Cleanup that never destroys data.</strong> A failed export removes its own temporary file, and never touches a file it didn’t create.</li></ul><h3>Safe by default</h3><p>A few defaults exist because exports usually leave your system and land somewhere else:</p><ul><li><strong>CSV injection protection is on.</strong> Spreadsheet applications treat a cell starting with =, +, - or @ as a formula. A user who names themselves =HYPERLINK(&quot;http://evil.example&quot;, &quot;click&quot;) can turn your export into a phishing link in someone&#39;s Excel. Following the OWASP recommendation, BeamExport prefixes such text with &#39;. Numbers are never changed, and you can turn this off for machine-to-machine exports.</li><li><strong>No row data in errors or telemetry.</strong> Exceptions end up in logs and error trackers. A failing mapper reports the row number and something like key :email not found, not the customer record. You can opt in to full records while debugging.</li><li><strong>Private files.</strong> Exports are created readable only by their owner (0600), and each staged download gets its own private directory.</li></ul><h3>Getting the CSV right</h3><p>Some details that are easy to get wrong:</p><ul><li><strong>Floats</strong> are written in their shortest exact form. A rounding formatter can silently turn 1.0e-12 into 0.0.</li><li><strong>Decimals</strong> never come out in scientific notation (1E+3), which spreadsheets and importers often misread.</li><li><strong>Lists, maps and tuples</strong> raise a clear error instead of being mangled. Converting [&quot;a&quot;, &quot;b&quot;] to a string naively gives &quot;ab&quot;.</li><li><strong>Header mismatches</strong> raise. If your headers don’t match a struct’s fields, you get an error, not a file full of empty columns.</li><li><strong>Typos in options</strong> raise with a “did you mean” hint, so sanitize_formula: false can&#39;t silently do nothing.</li></ul><h3>Performance</h3><p>Measured on Linux (OTP 26, Elixir 1.17) writing a 5-column synthetic dataset with to_file/3, single runs:</p><ul><li><strong>10,000 rows:</strong> 66 ms (~150k rows/s), 0.4 MB peak process memory</li><li><strong>100,000 rows:</strong> 477 ms (~210k rows/s), 0.4 MB peak process memory</li><li><strong>300,000 rows:</strong> 1.6 s (~190k rows/s), 0.3 MB peak process memory</li></ul><p>Memory stays flat as the export grows, because it depends on the chunk size, not the number of rows. Your numbers will depend on your database, row width and mapper.</p><h3>Limitations</h3><p>It’s an early 0.x release, so I’d rather be clear about what it doesn’t do yet:</p><ul><li>It writes CSV only.</li><li>Its test suite runs against SQLite. I haven’t run it against PostgreSQL or MySQL in CI yet.</li><li>Every running export holds one database connection while it reads rows, so you should still cap concurrent exports below your pool size.</li><li>A staged download only starts after the file is written, so very large exports belong in a background job.</li></ul><h3>Try it</h3><ul><li>Hex: <a href="https://hex.pm/packages/beam_export">https://hex.pm/packages/beam_export</a></li><li>Docs: <a href="https://hexdocs.pm/beam_export">https://hexdocs.pm/beam_export</a></li><li>GitHub: <a href="https://github.com/HataluliRandima/beam_export">https://github.com/HataluliRandima/beam_export</a></li></ul><p>Next on my list are streaming exports straight to S3-compatible storage, NDJSON and Parquet output, and a ready-made Oban worker for background exports. If you try BeamExport, especially on a large PostgreSQL or MySQL table, I’d love to hear how it goes. Issues and feedback on GitHub are very welcome.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af74a263f610" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Audit Logging in Phoenix Without Leaking Passwords]]></title>
            <link>https://medium.com/@hataluli.randima/audit-logging-in-phoenix-without-leaking-passwords-c8d3876aca9a?source=rss-fee3829a311------2</link>
            <guid isPermaLink="false">https://medium.com/p/c8d3876aca9a</guid>
            <category><![CDATA[phoenix-liveview]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[phoenix-framework]]></category>
            <category><![CDATA[ecto]]></category>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Hataluli Randima]]></dc:creator>
            <pubDate>Sun, 25 Oct 2026 13:08:29 GMT</pubDate>
            <atom:updated>2026-10-25T13:08:29.855Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Why your Ecto audit log misses </em><em>update_all, and other traps I found while building one.</em></p><p>Sooner or later, every app gets the question: <strong>“Who changed this record, and when?”</strong></p><p>Sometimes it comes from a compliance checklist. More often it comes during an incident, when a customer’s plan was downgraded, a price changed, or an admin account appeared from nowhere, and nobody can say how.</p><p>I recently built audit logging for a Phoenix app. The first version took ten minutes. Finding everything that was wrong with it took a lot longer. This post walks through the traps I hit, how to avoid them in plain Ecto, and how PostgreSQL triggers cover the changes your Elixir code never sees.</p><h3>The ten-minute version</h3><p>Here’s the audit log most of us write first:</p><pre>def update_user(user, attrs, actor) do<br>  changeset = User.changeset(user, attrs)</pre><pre>  with {:ok, updated} &lt;- Repo.update(changeset) do<br>    Repo.insert!(%AuditLog{<br>      action: &quot;update&quot;,<br>      table: &quot;users&quot;,<br>      record_id: to_string(updated.id),<br>      actor_id: to_string(actor.id),<br>      changes: changeset.changes<br>    })</pre><pre>    {:ok, updated}<br>  end<br>end</pre><p>It works in development and it passes the tests. It also has four problems.</p><h3>Trap 1: it isn’t atomic</h3><p>The update and the audit insert are two separate database calls. If the audit insert fails (a constraint, a timeout, a deploy at the wrong moment), the user is updated and there’s no record of it. An audit log with gaps is worse than none, because people trust it.</p><h3>Trap 2: it logs plaintext passwords</h3><p>This is the one that surprised me. If you used phx.gen.auth, your User schema has:</p><pre>field :password, :string, virtual: true, redact: true</pre><p>Then a password change runs a changeset that casts :password, so changeset.changes contains:</p><pre>%{password: &quot;correct horse battery staple&quot;, hashed_password: &quot;$2b$12$...&quot;}</pre><p>redact: true only hides the field from inspect/2. It does nothing to changeset.changes. So the naive version writes your users&#39; <strong>plaintext passwords</strong> into the audit table, and the hash as well for good measure.</p><p>Virtual fields are a common place for secrets: passwords, confirmation fields, one-time tokens. None of them are database columns, so none of them belong in an audit log of database changes.</p><h3>Trap 3: nested changesets come along</h3><p>If the form uses cast_assoc or cast_embed, changeset.changes holds <strong>whole </strong><strong>Ecto.Changeset structs</strong> for the children. Serialize those and you store their params (raw user input, including any secrets in the child form), plus validations, types, repo and more. You get a large, noisy JSON blob that leaks data.</p><h3>Trap 4: there’s no “before”</h3><p>changeset.changes only has the new values. &quot;Price changed to 49&quot; is much less useful than &quot;price changed from 19 to 49&quot;.</p><h3>Fixing it in plain Ecto</h3><h3>Use one transaction</h3><p>Ecto.Multi puts the change and the audit row in one transaction, so they succeed or fail together:</p><pre>Ecto.Multi.new()<br>|&gt; Ecto.Multi.update(:user, changeset)<br>|&gt; Ecto.Multi.insert(:audit, fn %{user: user} -&gt;<br>  AuditLog.changeset(%AuditLog{}, %{<br>    action: &quot;update&quot;,<br>    table: &quot;users&quot;,<br>    record_id: to_string(user.id),<br>    actor_id: to_string(actor.id),<br>    changes: diff(changeset)<br>  })<br>end)<br>|&gt; Repo.transaction()</pre><p>If either step fails, both roll back.</p><h3>Only diff real columns</h3><p>Ecto already knows which fields are persisted. __schema__(:fields) excludes virtual fields and associations:</p><pre>defp diff(changeset) do<br>  schema = changeset.data.__struct__<br>  persisted = schema.__schema__(:fields)<br>  applied = Ecto.Changeset.apply_changes(changeset)</pre><pre>  changeset.changes<br>  |&gt; Map.keys()<br>  |&gt; Enum.filter(&amp;(&amp;1 in persisted))<br>  |&gt; Map.new(fn field -&gt;<br>    {field, %{from: Map.get(changeset.data, field), to: Map.get(applied, field)}}<br>  end)<br>  |&gt; Map.reject(fn {_field, %{from: from, to: to}} -&gt; from == to end)<br>end</pre><p>This gets you three things:</p><ul><li><strong>No virtual fields:</strong> :password is never a candidate.</li><li><strong>No associations:</strong> child records should be audited as their own rows.</li><li><strong>Applied values:</strong> apply_changes/1 turns embedded changesets into plain structs, so you store the resulting data rather than the changeset internals.</li></ul><p>You’ll still want a deny-list for <strong>persisted</strong> secrets such as hashed_password and API tokens, and probably redaction (&quot;[REDACTED]&quot;) for fields like email where you want to know <em>that</em> something changed but not <em>what</em> it changed to.</p><h3>What your wrappers will never see</h3><p>Even with all of that, the audit log only covers changes that go through update_user/3. That leaves out:</p><ul><li>Repo.update_all(User, set: [plan: &quot;free&quot;]) in a background job</li><li>Repo.insert_all imports</li><li>a plain Repo.update someone wrote in a hurry</li><li>a migration that backfills data</li><li>someone fixing a row by hand in psql at 2am</li></ul><p>For an audit log, those can be the changes that matter most. The only layer that sees all of them is the database itself.</p><h3>Postgres triggers</h3><p>A row-level trigger runs for every insert, update and delete on a table, however it happened. The core idea fits on one screen:</p><pre>CREATE FUNCTION audit_capture() RETURNS trigger LANGUAGE plpgsql AS $$<br>DECLARE<br>  v_old jsonb := CASE WHEN TG_OP IN (&#39;UPDATE&#39;, &#39;DELETE&#39;) THEN to_jsonb(OLD) END;<br>  v_new jsonb := CASE WHEN TG_OP IN (&#39;INSERT&#39;, &#39;UPDATE&#39;) THEN to_jsonb(NEW) END;<br>  v_changes jsonb := &#39;{}&#39;;<br>  v_col text;<br>BEGIN<br>  FOR v_col IN SELECT jsonb_object_keys(coalesce(v_new, v_old)) LOOP<br>    CONTINUE WHEN v_col = &#39;hashed_password&#39;;<br>    CONTINUE WHEN coalesce(v_old -&gt; v_col, &#39;null&#39;) = coalesce(v_new -&gt; v_col, &#39;null&#39;);</pre><pre>    v_changes := v_changes || jsonb_build_object(<br>      v_col, jsonb_build_object(&#39;from&#39;, v_old -&gt; v_col, &#39;to&#39;, v_new -&gt; v_col)<br>    );<br>  END LOOP;</pre><pre>  INSERT INTO audit_events (action, &quot;table&quot;, changes, actor_id)<br>  VALUES (<br>    lower(TG_OP),<br>    TG_TABLE_NAME,<br>    v_changes,<br>    nullif(current_setting(&#39;app.actor_id&#39;, true), &#39;&#39;)<br>  );</pre><pre>  RETURN NULL;<br>END;<br>$$;</pre><pre>CREATE TRIGGER audit AFTER INSERT OR UPDATE OR DELETE ON users<br>FOR EACH ROW EXECUTE FUNCTION audit_capture();</pre><p>to_jsonb(OLD) and to_jsonb(NEW) turn the row into JSON, and the loop keeps only the columns that changed. Because the trigger runs inside the same transaction as the write, it&#39;s atomic for free.</p><h3>Getting the actor into the database</h3><p>The database doesn’t know who current_user is. The trick is a <strong>transaction-local setting</strong>:</p><pre>Repo.transaction(fn -&gt;<br>  Repo.query!(&quot;SELECT set_config(&#39;app.actor_id&#39;, $1, true)&quot;, [to_string(user.id)])<br>  Repo.update_all(User, set: [plan: &quot;free&quot;])<br>end)</pre><p>The true makes the setting local to the transaction, so it disappears at commit or rollback and never leaks to the next request using that pooled connection. The trigger reads it with current_setting(&#39;app.actor_id&#39;, true).</p><p>Some gotchas I hit along the way:</p><ul><li><strong>After the transaction, the setting is an empty string, not </strong><strong>NULL.</strong> Once a custom setting has been used in a session, it reverts to &#39;&#39;. Hence the nullif(..., &#39;&#39;).</li><li><strong>Savepoints don’t scope it.</strong> A Repo.transaction nested in another one becomes a savepoint, and the setting lasts until the <em>outermost</em> transaction ends. That includes Ecto&#39;s SQL sandbox in tests, which wraps every test in a transaction.</li><li><strong>Values come out as Postgres JSON.</strong> Decimals become JSON numbers and timestamps lose Ecto’s types, so trigger-recorded changes don’t look exactly like the ones your Elixir code records.</li><li><strong>Duplicate events.</strong> If you keep the Elixir-side audit (which knows more, like schema-level redaction and request metadata) <em>and</em> add triggers, every normal write is recorded twice. One fix is for the Elixir side to set a transaction-local “skip” flag just before its own statement and clear it straight after. The trigger checks the flag, and everything else in the transaction is still captured.</li></ul><h3>Packaging it up: AuditTrailEx</h3><p>I wrapped all of this into a library, <a href="https://hex.pm/packages/audit_trail_ex"><strong>AuditTrailEx</strong></a>. Setup is a dependency and a migration:</p><pre># mix.exs<br>{:audit_trail_ex, &quot;~&gt; 0.2.0&quot;}</pre><pre># a migration<br>def up, do: AuditTrailEx.Migration.up()<br>def down, do: AuditTrailEx.Migration.down()</pre><pre># config/config.exs<br>config :audit_trail_ex,<br>  excluded_fields: [:hashed_password, :current_password],<br>  redacted_fields: [:email]</pre><p>Then use it in place of Repo writes:</p><pre>{:ok, user} =<br>  AuditTrailEx.update(Repo, User.changeset(user, attrs),<br>    actor: current_user,<br>    metadata: %{request_id: request_id}<br>  )</pre><p>It handles everything above: one transaction, persisted columns only, before-and-after values, exclusion and redaction (globally, per schema or per call), and Ecto.Multi support. It also turns events into readable text:</p><pre>AuditTrailEx.history(Repo, User, user.id)<br>|&gt; List.first()<br>|&gt; AuditTrailEx.describe_text()<br># Update MyApp.Accounts.User [42]<br>#<br># Name changed<br>#   From: &quot;John&quot;<br>#   To:   &quot;Johnny&quot;</pre><p>The trigger approach is optional, and both approaches write to the same table:</p><pre># a migration<br>AuditTrailEx.Trigger.install()<br>AuditTrailEx.Trigger.create(MyApp.Accounts.User)</pre><pre># config: AuditTrailEx tells the trigger to skip writes it already recorded<br>config :audit_trail_ex, trigger_capture: true</pre><pre>AuditTrailEx.with_context(Repo, [actor: current_user], fn -&gt;<br>  Repo.update_all(User, set: [plan: &quot;free&quot;])<br>end)</pre><h3>Grouping events by transaction</h3><p>One request often changes several tables: an order, its line items, and a stock count updated by a trigger. To answer “what did this request change?”, every audit row needs to know which transaction wrote it.</p><p>Postgres has an id for that: pg_current_xact_id(), which is unique for the life of the database. Make it the <strong>column default</strong> and every insert into the audit table records it, whether it came from Elixir or from a trigger, with no extra query:</p><pre>add :transaction_id, :bigint, default: fragment(&quot;pg_current_xact_id()::text::bigint&quot;)</pre><p>One gotcha if you add this to an <strong>existing</strong> table: adding a column with a volatile default makes Postgres rewrite the table and stamp every existing row with the migration’s own transaction id. Add the column first, then ALTER COLUMN ... SET DEFAULT in a separate step.</p><p>AuditTrailEx does this for you:</p><pre>[event | _] = AuditTrailEx.history(Repo, User, user.id)</pre><pre># Everything committed in the same transaction, across tables<br>AuditTrailEx.by_transaction(Repo, event)</pre><p><strong>Limitations, to be upfront:</strong> it’s an early 0.x release, it’s mainly tested on PostgreSQL (triggers need 13 or later), exclusion is by field name, and TRUNCATE isn&#39;t captured. Established libraries like <a href="https://hex.pm/packages/paper_trail">PaperTrail</a>, <a href="https://hex.pm/packages/ex_audit">ExAudit</a> and <a href="https://hex.pm/packages/carbonite">Carbonite</a> are worth a look too. Pick the one that matches how you want to capture changes.</p><h3>Takeaways</h3><p>Even if you never use the library, these are worth checking in your own audit log:</p><ol><li><strong>Write the audit row in the same transaction</strong> as the change.</li><li><strong>Diff </strong><strong>__schema__(:fields), not </strong><strong>changeset.changes</strong>, so virtual fields and nested changesets never reach the log. Check what yours does with a phx.gen.auth password change.</li><li><strong>Store before and after values</strong>, not just the new ones.</li><li><strong>Remember what your Elixir code can’t see.</strong> update_all, raw SQL and manual fixes need database triggers.</li><li><strong>Record the transaction id</strong>, so you can see everything one request changed, not just one row.</li></ol><p>Next on the roadmap is <strong>read-only reconstruction</strong>: rebuilding a record as it was at a given time. (Automatic revert is on hold after feedback from the community: most people want to <em>look</em> at past state, and reverting changes across tables safely is much harder.) The open question is how to represent fields that can’t be rebuilt, such as redacted ones or anything from before auditing started. If you have opinions, I’d love to hear them in the <a href="https://forum.elixirforum.com/t/audittrailex-transaction-safe-audit-logging-for-ecto-with-optional-postgres-triggers/76952">Elixir Forum thread</a> or on <a href="https://github.com/HataluliRandima/audit">GitHub</a>.</p><p><em>Thanks for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c8d3876aca9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>