Skip to content

Instantly share code, notes, and snippets.

@tomaspozo
Last active October 21, 2025 21:33
Show Gist options
  • Select an option

  • Save tomaspozo/c96017c9d9de4b484cc41f5d021db389 to your computer and use it in GitHub Desktop.

Select an option

Save tomaspozo/c96017c9d9de4b484cc41f5d021db389 to your computer and use it in GitHub Desktop.
-- Create 300 dummy tables with RLS enabled and a default select policy each
DO $$
DECLARE
i INT;
table_name TEXT;
BEGIN
FOR i IN 1..300 LOOP
table_name := format('dummy_table_%s', i);
EXECUTE format($sql$
CREATE TABLE IF NOT EXISTS %I (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
description TEXT
);
$sql$, table_name);
EXECUTE format('ALTER TABLE %I ENABLE ROW LEVEL SECURITY;', table_name);
-- Create policy to allow authenticated users to select
EXECUTE format($sql$
CREATE POLICY select_authenticated ON %I
FOR SELECT
TO authenticated
USING (true);
$sql$, table_name);
END LOOP;
END
$$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment