Merge pull request #106 from MR-medreport/MED-97
feat(MED-97): migrations fix timestamps
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
-- Drop existing constraint and index for analysis_response_elements
|
||||
DROP INDEX IF EXISTS "medreport"."analysis_response_elements_unique_by_response_and_element";
|
||||
ALTER TABLE "medreport"."analysis_response_elements"
|
||||
DROP CONSTRAINT IF EXISTS "analysis_response_elements_unique_by_response_and_element";
|
||||
DROP INDEX IF EXISTS "medreport"."analysis_response_elements_unique_by_response_and_element";
|
||||
|
||||
-- Create proper unique constraint that works with ON CONFLICT
|
||||
ALTER TABLE "medreport"."analysis_response_elements"
|
||||
|
||||
@@ -50,23 +50,10 @@ begin
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- 2. Add RLS policy for authenticated users to read distribution schedules
|
||||
create policy "Users can view distribution schedules for their companies"
|
||||
on "medreport"."benefit_distribution_schedule"
|
||||
for select
|
||||
to authenticated
|
||||
using (
|
||||
company_id in (
|
||||
select account_id
|
||||
from medreport.accounts_memberships
|
||||
where user_id = auth.uid()
|
||||
)
|
||||
);
|
||||
|
||||
-- 3. Grant permissions to authenticated users
|
||||
-- 2. Grant permissions to authenticated users
|
||||
grant select, insert, update, delete on table "medreport"."benefit_distribution_schedule" to authenticated;
|
||||
|
||||
-- 4. Grant execute permissions to all functions
|
||||
-- 3. Grant execute permissions to all functions
|
||||
grant execute on function medreport.get_account_balance(uuid) to authenticated;
|
||||
grant execute on function medreport.distribute_health_benefits(uuid, numeric, text) to authenticated;
|
||||
grant execute on function medreport.consume_account_balance(uuid, numeric, text, text) to authenticated;
|
||||
@@ -76,7 +63,7 @@ grant execute on function medreport.trigger_benefit_distribution(uuid) to authen
|
||||
grant execute on function medreport.trigger_distribute_benefits() to authenticated;
|
||||
grant execute on function medreport.process_periodic_benefit_distributions() to authenticated;
|
||||
|
||||
-- 5. Ensure trigger function has security definer
|
||||
-- 4. Ensure trigger function has security definer
|
||||
create or replace function medreport.trigger_distribute_benefits()
|
||||
returns trigger
|
||||
language plpgsql
|
||||
@@ -109,6 +96,5 @@ begin
|
||||
end;
|
||||
$$;
|
||||
|
||||
-- 6. Grant execute permission to the updated trigger function
|
||||
-- 5. Grant execute permission to the updated trigger function
|
||||
grant execute on function medreport.trigger_distribute_benefits() to authenticated, service_role;
|
||||
|
||||
Reference in New Issue
Block a user