-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcheck_facilities_structure.sql
More file actions
73 lines (63 loc) · 2.52 KB
/
check_facilities_structure.sql
File metadata and controls
73 lines (63 loc) · 2.52 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
-- CHECK FACILITIES TABLE STRUCTURE
-- Run this in Supabase SQL Editor
-- 1. Check current table structure
SELECT '=== CURRENT FACILITIES TABLE STRUCTURE ===' as info;
SELECT
column_name,
data_type,
is_nullable,
column_default
FROM information_schema.columns
WHERE table_name = 'facilities'
ORDER BY ordinal_position;
-- 2. Check if we need to add missing columns
SELECT '=== CHECKING FOR MISSING COLUMNS ===' as info;
-- Check if contact_phone exists
SELECT
CASE
WHEN EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'facilities' AND column_name = 'contact_phone')
THEN 'contact_phone column exists'
ELSE 'contact_phone column MISSING'
END as status;
-- Check if contact_email exists
SELECT
CASE
WHEN EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'facilities' AND column_name = 'contact_email')
THEN 'contact_email column exists'
ELSE 'contact_email column MISSING'
END as status;
-- Check if website_url exists
SELECT
CASE
WHEN EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'facilities' AND column_name = 'website_url')
THEN 'website_url column exists'
ELSE 'website_url column MISSING'
END as status;
-- 3. Add missing columns if they don't exist
DO $$
BEGIN
-- Add contact_phone if it doesn't exist
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'facilities' AND column_name = 'contact_phone') THEN
ALTER TABLE facilities ADD COLUMN contact_phone TEXT;
RAISE NOTICE 'Added contact_phone column to facilities table';
END IF;
-- Add contact_email if it doesn't exist
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'facilities' AND column_name = 'contact_email') THEN
ALTER TABLE facilities ADD COLUMN contact_email TEXT;
RAISE NOTICE 'Added contact_email column to facilities table';
END IF;
-- Add website_url if it doesn't exist
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'facilities' AND column_name = 'website_url') THEN
ALTER TABLE facilities ADD COLUMN website_url TEXT;
RAISE NOTICE 'Added website_url column to facilities table';
END IF;
END $$;
-- 4. Verify final structure
SELECT '=== FINAL FACILITIES TABLE STRUCTURE ===' as info;
SELECT
column_name,
data_type,
is_nullable
FROM information_schema.columns
WHERE table_name = 'facilities'
ORDER BY ordinal_position;