{"id":13467914,"url":"https://github.com/supabase/supa_audit","last_synced_at":"2026-05-20T09:30:18.803Z","repository":{"id":37094020,"uuid":"457547532","full_name":"supabase/supa_audit","owner":"supabase","description":"Generic Table Auditing","archived":false,"fork":false,"pushed_at":"2024-01-03T16:04:53.000Z","size":49,"stargazers_count":660,"open_issues_count":6,"forks_count":40,"subscribers_count":35,"default_branch":"main","last_synced_at":"2025-02-15T14:36:32.885Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/supabase.png","metadata":{"funding":{"github":["supabase"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-02-09T22:20:42.000Z","updated_at":"2025-01-29T16:52:09.000Z","dependencies_parsed_at":"2024-01-18T04:51:26.593Z","dependency_job_id":"4b3918ab-35e5-4eb2-ab27-45b1fc058cea","html_url":"https://github.com/supabase/supa_audit","commit_stats":{"total_commits":44,"total_committers":6,"mean_commits":7.333333333333333,"dds":"0.20454545454545459","last_synced_commit":"4f527f062e85ec0549c45009c3860d50ddf7f282"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fsupa_audit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fsupa_audit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fsupa_audit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supabase%2Fsupa_audit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supabase","download_url":"https://codeload.github.com/supabase/supa_audit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240127111,"owners_count":19751941,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T15:01:02.455Z","updated_at":"2026-05-20T09:30:18.766Z","avatar_url":"https://github.com/supabase.png","language":"PLpgSQL","funding_links":["https://github.com/sponsors/supabase"],"categories":["PLpgSQL","others"],"sub_categories":[],"readme":"# `supa_audit`\n\n\u003cp\u003e\n\u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/postgresql-12+-blue.svg\" alt=\"PostgreSQL version\" height=\"18\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/supabase/supa_audit/actions\"\u003e\u003cimg src=\"https://github.com/supabase/supa_audit/actions/workflows/test.yaml/badge.svg\" alt=\"Tests\" height=\"18\"\u003e\u003c/a\u003e\n\n\u003c/p\u003e\n\n---\n\n**Source Code**: \u003ca href=\"https://github.com/supabase/supa_audit\" target=\"_blank\"\u003ehttps://github.com/supabase/supa_audit\u003c/a\u003e\n\n---\n\nThe `supa_audit` PostgreSQL extension is a generic solution for tracking changes to tables' data over time.\n\nThe audit table, `audit.record_version`, leverages each records primary key values to produce a stable `record_id::uuid`, enabling efficient (linear time) history queries.\n\n\n## Usage\n\n```sql\ncreate extension supa_audit cascade;\n\ncreate table public.account(\n    id int primary key,\n    name text not null\n);\n\n-- Enable auditing\nselect audit.enable_tracking('public.account'::regclass);\n\n-- Insert a record\ninsert into public.account(id, name)\nvalues (1, 'Foo Barsworth');\n\n-- Update a record\nupdate public.account\nset name = 'Foo Barsworht III'\nwhere id = 1;\n\n-- Delete a record\ndelete from public.account\nwhere id = 1;\n\n-- Truncate the table\ntruncate table public.account;\n\n-- Review the history\nselect\n    *\nfrom\n    audit.record_version;\n\n/*\n id |              record_id               |            old_record_id             |    op    |               ts                | table_oid | table_schema | table_name |                 record                 |             old_record\n----+--------------------------------------+--------------------------------------+----------+---------------------------------+-----------+--------------+------------+----------------------------------------+------------------------------------\n  1 | 57ca384e-f24c-5af5-b361-a057aeac506c |                                      | INSERT   | Thu Feb 10 17:02:25.621095 2022 |     16439 | public       | account    | {\"id\": 1, \"name\": \"Foo Barsworth\"}     |\n  2 | 57ca384e-f24c-5af5-b361-a057aeac506c | 57ca384e-f24c-5af5-b361-a057aeac506c | UPDATE   | Thu Feb 10 17:02:25.622151 2022 |     16439 | public       | account    | {\"id\": 1, \"name\": \"Foo Barsworht III\"} | {\"id\": 1, \"name\": \"Foo Barsworth\"}\n  3 |                                      | 57ca384e-f24c-5af5-b361-a057aeac506c | DELETE   | Thu Feb 10 17:02:25.622495 2022 |     16439 | public       | account    |                                        | {\"id\": 1, \"name\": \"Foo Barsworth III\"}\n  4 |                                      |                                      | TRUNCATE | Thu Feb 10 17:02:25.622779 2022 |     16439 | public       | account    |                                        |\n(4 rows)\n*/\n\n-- Disable auditing\nselect audit.disable_tracking('public.account'::regclass);\n```\n\n## Test\n\n### Run the Tests\n\n```sh\nnix-shell --run \"pg_13_supa_audit make installcheck\"\n```\n\n### Adding Tests\n\nTests are located in `test/sql/` and the expected output is in `test/expected/`\n\nThe output of the most recent test run is stored in `results/`.\n\nWhen the output for a test in `results/` is correct, copy it to `test/expected/` and the test will pass.\n\n## Interactive Prompt\n\n```sh\nnix-shell --run \"pg_13_supa_audit psql\"\n```\n\n## Performance\n\n\n### Write Throughput\nAuditing tables reduces throughput of inserts, updates, and deletes.\n\nIt is not recommended to enable tracking on tables with a peak write throughput over 3k ops/second.\n\n\n### Querying\n\nWhen querying a table's history, filter on the indexed `table_oid` rather than the `table_name` and `schema_name` columns.\n\n```sql\nselect\n    *\nfrom\n    audit.record_version\nwhere\n    table_oid = 'public.account'::regclass::oid;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase%2Fsupa_audit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupabase%2Fsupa_audit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupabase%2Fsupa_audit/lists"}