{"id":20704152,"url":"https://github.com/solidsnack/macaroon","last_synced_at":"2025-03-11T04:40:56.962Z","repository":{"id":34292749,"uuid":"38189182","full_name":"solidsnack/macaroon","owner":"solidsnack","description":"Postgres introspection and macros","archived":false,"fork":false,"pushed_at":"2023-01-01T06:41:48.000Z","size":24,"stargazers_count":18,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-05T17:08:16.758Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/solidsnack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":"audit.sql","citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-28T06:33:01.000Z","updated_at":"2025-02-17T16:51:34.000Z","dependencies_parsed_at":"2023-01-15T05:57:45.756Z","dependency_job_id":null,"html_url":"https://github.com/solidsnack/macaroon","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidsnack%2Fmacaroon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidsnack%2Fmacaroon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidsnack%2Fmacaroon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solidsnack%2Fmacaroon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/solidsnack","download_url":"https://codeload.github.com/solidsnack/macaroon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242973887,"owners_count":20215245,"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-11-17T01:11:13.028Z","updated_at":"2025-03-11T04:40:56.921Z","avatar_url":"https://github.com/solidsnack.png","language":"PLpgSQL","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nMany tricky table configurations -- for example, logged tables and partitioned\ntables -- would seem to be amenable to mechanical derivation. The SQL standard\nprovides for fairly rich introspection capabilities -- on par with any object\noriented language -- so it stands to reason that we should be able to use\nmetaprogramming to derive advanced table configurations mechanically.\n\nThe `meta` schema in `meta.sql` should be loaded before loading the others. To\nload all the schemas together, run `\\i macaroon.psql` at the `psql` prompt.\n\nCreating Tables for Auditing \u0026 Versioning\n-------------------------------------------\n\nImagine that your application has tables in the `app` namespace; and you'd like\nto log past row versions and metadata about changes to the `state` and `events`\nschemas, respectively. You can idempotently configure both audit and version\nstracking by `SELECT`ing tables in the `app` namespace that are not already\ntracked and passing them to the setup functions:\n\n```sql\nSELECT tab,\n       temporal.temporal(tab, 'state'),\n       audit.audit(tab, 'events')\n  FROM pg_tables,\n       LATERAL (SELECT (schemaname||'.'||tablename)::regclass AS tab)\n            AS casted_to_regclass\n WHERE schemaname = 'app'\n   AND tab NOT IN (SELECT logged FROM temporal.logged\n                    UNION\n                   SELECT audited FROM audit.audited);\n\n      tab      │    temporal     │      audit\n───────────────┼─────────────────┼──────────────────\n app.user_info │ state.user_info │ events.user_info\n app.telephone │ state.telephone │ events.telephone\n app.cpu       │ state.cpu       │ events.cpu\n ...           │ ...             │ ...\n```\n\n\nUsing The Auditing \u0026 Versioning Tables\n--------------------------------------\n\nThe audit and temporal tables for each table that is tracked can be joined on\nthe `txid` column to see all the actions that took place during a particular\ntransaction.\n\n\nA Note About Migrations\n-----------------------\n\nThe audit tables are indifferent to migrations -- they do not store any row\ndata.\n\nThe temporal tables store `JSONB`, so they're also indifferent to migrations.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidsnack%2Fmacaroon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolidsnack%2Fmacaroon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolidsnack%2Fmacaroon/lists"}