© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3mo ago•
2 replies
nicetomytyuk

RLS not applied to the view after migration

I have a RLS on the root table from which a view is created, recently I updated the view via a migration by doing a
drop view ...
drop view ...
and creating it again.

The issue is that after that, the view seems skipping the RLS rules while still working on the table.

The migration I ran:

-- 1) Add `updated_at` to shops (backfilled with default for existing rows)
alter table public.shops
  add column if not exists updated_at timestamp with time zone
  not null default (now() at time zone 'gmt-2'::text);

-- 2) (Re)create the updated_at trigger for shops
drop trigger if exists zz_handle_updated_at on public.shops;
create trigger zz_handle_updated_at
before update on public.shops
for each row
execute function moddatetime('updated_at');

-- 3) Drop the old view before recreating
drop view if exists public.shops_view;

-- 4) Extend the view with phone, computed address, created_at, updated_at
create or replace view public.shops_view as
select
  s.id   as shop_id,
  s.code as shop_code,
  s.name as shop_name,

  -- new: expose phone
  s.phone as shop_phone,

  -- new: computed, gracefully joins address parts that exist
  nullif(
    trim(both ', ' from concat_ws(
      ', ',
      nullif(s.address, ''),
      nullif(concat_ws(' ', nullif(s.postal_code, ''), nullif(s.city, '')), ''),
      nullif(s.province, '')
    )),
    ''
  ) as shop_address,

  c.id         as company_id,
  c.name       as company_name,
  c.created_by as company_created_by,

  -- new: timestamps so you can sort by recency
  s.created_at,
  s.updated_at
from
  public.shops s
  join public.companies c on s.company = c.id;
-- 1) Add `updated_at` to shops (backfilled with default for existing rows)
alter table public.shops
  add column if not exists updated_at timestamp with time zone
  not null default (now() at time zone 'gmt-2'::text);

-- 2) (Re)create the updated_at trigger for shops
drop trigger if exists zz_handle_updated_at on public.shops;
create trigger zz_handle_updated_at
before update on public.shops
for each row
execute function moddatetime('updated_at');

-- 3) Drop the old view before recreating
drop view if exists public.shops_view;

-- 4) Extend the view with phone, computed address, created_at, updated_at
create or replace view public.shops_view as
select
  s.id   as shop_id,
  s.code as shop_code,
  s.name as shop_name,

  -- new: expose phone
  s.phone as shop_phone,

  -- new: computed, gracefully joins address parts that exist
  nullif(
    trim(both ', ' from concat_ws(
      ', ',
      nullif(s.address, ''),
      nullif(concat_ws(' ', nullif(s.postal_code, ''), nullif(s.city, '')), ''),
      nullif(s.province, '')
    )),
    ''
  ) as shop_address,

  c.id         as company_id,
  c.name       as company_name,
  c.created_by as company_created_by,

  -- new: timestamps so you can sort by recency
  s.created_at,
  s.updated_at
from
  public.shops s
  join public.companies c on s.company = c.id;


While the RLS applied to
shops
shops
is working as I tested it properly.
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

View RLS
SupabaseSSupabase / help-and-questions
2mo ago
Migration is not being applied. Prod app down.
SupabaseSSupabase / help-and-questions
3d ago
Database not working after migration to CF Workers
SupabaseSSupabase / help-and-questions
2mo ago
Upgrade Not Applied After Payment – Account Still Not Updated
SupabaseSSupabase / help-and-questions
3mo ago