Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
416c2e2
1
Parent(s):
f565e50
refactor: move UUID function to schema.sql and remove migrations folder
Browse files- Moved string_to_portfolio_uuid function from migrations to schema.sql
- Removed database/migrations/ folder (not needed for new project)
- All database functions now in single schema.sql file
database/migrations/add_uuid_functions.sql
DELETED
|
@@ -1,20 +0,0 @@
|
|
| 1 |
-
-- Enable uuid-ossp extension for uuid_generate_v5
|
| 2 |
-
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
| 3 |
-
|
| 4 |
-
-- Helper function to convert strings to UUIDs
|
| 5 |
-
CREATE OR REPLACE FUNCTION string_to_portfolio_uuid(input_string TEXT)
|
| 6 |
-
RETURNS UUID
|
| 7 |
-
LANGUAGE plpgsql
|
| 8 |
-
IMMUTABLE
|
| 9 |
-
SECURITY INVOKER
|
| 10 |
-
SET search_path = ''
|
| 11 |
-
AS $$
|
| 12 |
-
BEGIN
|
| 13 |
-
-- Use URL namespace for consistency
|
| 14 |
-
-- Fully qualify function names when search_path is empty
|
| 15 |
-
RETURN public.uuid_generate_v5(public.uuid_ns_url(), input_string);
|
| 16 |
-
END;
|
| 17 |
-
$$;
|
| 18 |
-
|
| 19 |
-
-- Grant execute to authenticated and anon roles
|
| 20 |
-
GRANT EXECUTE ON FUNCTION string_to_portfolio_uuid TO authenticated, anon;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
database/schema.sql
CHANGED
|
@@ -4,6 +4,24 @@
|
|
| 4 |
-- Enable UUID extension (if not already enabled)
|
| 5 |
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
-- Users table (linked to Supabase Auth - CRITICAL FIX)
|
| 8 |
CREATE TABLE IF NOT EXISTS users (
|
| 9 |
id UUID PRIMARY KEY REFERENCES auth.users(id) ON DELETE CASCADE,
|
|
|
|
| 4 |
-- Enable UUID extension (if not already enabled)
|
| 5 |
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
| 6 |
|
| 7 |
+
-- Helper function to convert strings to UUIDs (for demo portfolio IDs)
|
| 8 |
+
CREATE OR REPLACE FUNCTION string_to_portfolio_uuid(input_string TEXT)
|
| 9 |
+
RETURNS UUID
|
| 10 |
+
LANGUAGE plpgsql
|
| 11 |
+
IMMUTABLE
|
| 12 |
+
SECURITY INVOKER
|
| 13 |
+
SET search_path = ''
|
| 14 |
+
AS $$
|
| 15 |
+
BEGIN
|
| 16 |
+
-- Use URL namespace for consistency
|
| 17 |
+
-- Fully qualify function names when search_path is empty
|
| 18 |
+
RETURN public.uuid_generate_v5(public.uuid_ns_url(), input_string);
|
| 19 |
+
END;
|
| 20 |
+
$$;
|
| 21 |
+
|
| 22 |
+
-- Grant execute to authenticated and anon roles
|
| 23 |
+
GRANT EXECUTE ON FUNCTION string_to_portfolio_uuid TO authenticated, anon;
|
| 24 |
+
|
| 25 |
-- Users table (linked to Supabase Auth - CRITICAL FIX)
|
| 26 |
CREATE TABLE IF NOT EXISTS users (
|
| 27 |
id UUID PRIMARY KEY REFERENCES auth.users(id) ON DELETE CASCADE,
|