alter table "public"."accounts" add column "has_consent_anonymized_company_statistics" boolean;

alter table "audit"."log_entries" alter column "record_key" set data type text using "record_key"::text;

create policy "insert_own"
on "audit"."log_entries"
as permissive
for insert
to authenticated
with check ((( SELECT auth.uid() AS uid) = changed_by));

drop policy "service_role_all" on "audit"."sync_entries";

create policy "service_role_all"
on "audit"."sync_entries"
as permissive
for all
to service_role
using (true);

CREATE TRIGGER log_account_change AFTER DELETE OR UPDATE ON public.accounts FOR EACH ROW EXECUTE FUNCTION audit.log_audit_changes();
GRANT USAGE ON SCHEMA audit TO authenticated;
grant insert on table audit.log_entries to authenticated;