-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathseed.sql
More file actions
97 lines (92 loc) · 2.38 KB
/
seed.sql
File metadata and controls
97 lines (92 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
-- ============================================================
-- Stampee: Demo Admin Seed Script
-- Local/development use only.
-- ============================================================
-- Run this in the Supabase SQL Editor AFTER running migration.sql.
-- This creates a single demo admin (owner) account with known
-- credentials for local or development environments only.
--
-- Demo credentials:
-- Email : admin@stampee.local
-- Password: Admin1234
-- Slug : demo
-- ============================================================
do $$
declare
v_uid uuid := gen_random_uuid();
v_email text := 'admin@stampee.local';
v_password text := 'Admin1234';
v_business_name text := 'Demo Business';
v_slug text := 'demo';
begin
-- Skip if the admin account already exists
if exists (select 1 from auth.users where email = v_email) then
raise notice 'Demo admin already exists. Skipping seed.';
return;
end if;
-- Create the Supabase auth user
insert into auth.users (
id,
instance_id,
aud,
role,
email,
encrypted_password,
email_confirmed_at,
raw_user_meta_data,
raw_app_meta_data,
created_at,
updated_at,
is_sso_user
) values (
v_uid,
'00000000-0000-0000-0000-000000000000',
'authenticated',
'authenticated',
v_email,
crypt(v_password, gen_salt('bf')),
now(),
jsonb_build_object(
'role', 'owner',
'business_name', v_business_name,
'slug', v_slug
),
jsonb_build_object('provider', 'email', 'providers', array_to_json(array['email'])),
now(),
now(),
false
);
-- Create the identity record (required for email/password sign-in)
insert into auth.identities (
id,
user_id,
identity_data,
provider,
provider_id,
last_sign_in_at,
created_at,
updated_at
) values (
v_uid,
v_uid,
jsonb_build_object('sub', v_uid::text, 'email', v_email),
'email',
v_uid::text,
now(),
now(),
now()
);
-- The handle_new_user trigger auto-creates the profile row.
-- Update it to set verified status and the correct slug.
update public.profiles
set
status = 'verified',
slug = v_slug,
tier = 'free'
where id = v_uid;
raise notice 'Demo admin created successfully.';
raise notice ' Email : %', v_email;
raise notice ' Password: %', v_password;
raise notice ' Slug : %', v_slug;
end;
$$;