realtimex-crm 0.3.2 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,13 +61,78 @@ export function DatabaseSetupGuide({
61
61
  </div>
62
62
  </div>
63
63
 
64
- {/* Option 1: Supabase CLI */}
64
+ {/* Option 1: Direct SQL File */}
65
65
  <div className="space-y-3">
66
66
  <div className="flex items-center gap-2">
67
67
  <div className="flex items-center justify-center w-6 h-6 rounded-full bg-primary text-primary-foreground text-sm font-bold">
68
68
  1
69
69
  </div>
70
- <h3 className="font-semibold">Using Supabase CLI (Recommended)</h3>
70
+ <h3 className="font-semibold">Quick Setup (Recommended)</h3>
71
+ </div>
72
+ <div className="ml-8 space-y-3">
73
+ <p className="text-sm text-muted-foreground">
74
+ Download and run the combined migration file:
75
+ </p>
76
+
77
+ <ol className="list-decimal list-inside space-y-2 text-sm text-muted-foreground">
78
+ <li>
79
+ Download{" "}
80
+ <a
81
+ href="https://raw.githubusercontent.com/therealtimex/realtimex-crm/main/public/setup.sql"
82
+ target="_blank"
83
+ rel="noopener noreferrer"
84
+ className="text-primary hover:underline inline-flex items-center gap-1"
85
+ download
86
+ >
87
+ setup.sql
88
+ <ExternalLink className="h-3 w-3" />
89
+ </a>
90
+ </li>
91
+ <li>
92
+ Open your{" "}
93
+ <a
94
+ href={`https://supabase.com/dashboard/project/${projectRef}/sql/new`}
95
+ target="_blank"
96
+ rel="noopener noreferrer"
97
+ className="text-primary hover:underline inline-flex items-center gap-1"
98
+ >
99
+ Supabase SQL Editor
100
+ <ExternalLink className="h-3 w-3" />
101
+ </a>
102
+ </li>
103
+ <li>
104
+ Copy the entire contents of setup.sql and paste into the SQL Editor
105
+ </li>
106
+ <li>
107
+ Click "Run" to execute all migrations at once
108
+ </li>
109
+ <li>
110
+ Reload this page after completion
111
+ </li>
112
+ </ol>
113
+
114
+ {projectRef && (
115
+ <Button asChild variant="outline" className="w-full">
116
+ <a
117
+ href={`https://supabase.com/dashboard/project/${projectRef}/sql/new`}
118
+ target="_blank"
119
+ rel="noopener noreferrer"
120
+ >
121
+ <ExternalLink className="h-4 w-4 mr-2" />
122
+ Open SQL Editor
123
+ </a>
124
+ </Button>
125
+ )}
126
+ </div>
127
+ </div>
128
+
129
+ {/* Option 2: Supabase CLI */}
130
+ <div className="space-y-3">
131
+ <div className="flex items-center gap-2">
132
+ <div className="flex items-center justify-center w-6 h-6 rounded-full bg-primary text-primary-foreground text-sm font-bold">
133
+ 2
134
+ </div>
135
+ <h3 className="font-semibold">Using Supabase CLI</h3>
71
136
  </div>
72
137
  <div className="ml-8 space-y-3">
73
138
  <div>
@@ -115,22 +180,22 @@ export function DatabaseSetupGuide({
115
180
  </div>
116
181
  </div>
117
182
 
118
- {/* Option 2: SQL Editor */}
183
+ {/* Option 3: Individual Migrations */}
119
184
  <div className="space-y-3">
120
185
  <div className="flex items-center gap-2">
121
186
  <div className="flex items-center justify-center w-6 h-6 rounded-full bg-primary text-primary-foreground text-sm font-bold">
122
- 2
187
+ 3
123
188
  </div>
124
- <h3 className="font-semibold">Using Supabase SQL Editor</h3>
189
+ <h3 className="font-semibold">Advanced: Run Individual Migrations</h3>
125
190
  </div>
126
191
  <div className="ml-8 space-y-3">
127
192
  <p className="text-sm text-muted-foreground">
128
- Manually run the SQL migrations in your Supabase SQL Editor:
193
+ For advanced users who want to review each migration:
129
194
  </p>
130
195
 
131
196
  <ol className="list-decimal list-inside space-y-2 text-sm text-muted-foreground">
132
197
  <li>
133
- Download migrations from{" "}
198
+ Browse migrations at{" "}
134
199
  <a
135
200
  href="https://github.com/therealtimex/realtimex-crm/tree/main/supabase/migrations"
136
201
  target="_blank"
@@ -154,25 +219,12 @@ export function DatabaseSetupGuide({
154
219
  </a>
155
220
  </li>
156
221
  <li>
157
- Run each migration file in order (by date in filename)
222
+ Run each migration file in chronological order (by date in filename)
158
223
  </li>
159
224
  <li>
160
225
  Reload this page after all migrations are complete
161
226
  </li>
162
227
  </ol>
163
-
164
- {projectRef && (
165
- <Button asChild variant="outline" className="w-full">
166
- <a
167
- href={`https://supabase.com/dashboard/project/${projectRef}/sql/new`}
168
- target="_blank"
169
- rel="noopener noreferrer"
170
- >
171
- <ExternalLink className="h-4 w-4 mr-2" />
172
- Open SQL Editor
173
- </a>
174
- </Button>
175
- )}
176
228
  </div>
177
229
  </div>
178
230
 
@@ -0,0 +1,98 @@
1
+ # Database Migrations
2
+
3
+ This directory contains all the SQL migration files needed to set up the RealTimeX CRM database schema.
4
+
5
+ ## Quick Setup (Recommended)
6
+
7
+ The easiest way to set up your database is to use the combined `setup.sql` file:
8
+
9
+ 1. Download [setup.sql](https://raw.githubusercontent.com/therealtimex/realtimex-crm/main/public/setup.sql)
10
+ 2. Open your [Supabase SQL Editor](https://supabase.com/dashboard)
11
+ 3. Copy the entire contents of `setup.sql` and paste into the SQL Editor
12
+ 4. Click "Run" to execute all migrations at once
13
+
14
+ ## Using Supabase CLI
15
+
16
+ If you prefer using the CLI:
17
+
18
+ ```bash
19
+ # Install Supabase CLI
20
+ npm install -g supabase
21
+
22
+ # Clone this repository
23
+ git clone https://github.com/therealtimex/realtimex-crm.git
24
+ cd realtimex-crm
25
+
26
+ # Link to your Supabase project
27
+ supabase link --project-ref YOUR_PROJECT_REF
28
+
29
+ # Push migrations
30
+ supabase db push
31
+ ```
32
+
33
+ ## Migration Files
34
+
35
+ These migrations are applied in chronological order (by date in filename):
36
+
37
+ 1. **20240730075029_init_db.sql** - Creates core tables (contacts, companies, deals, sales, tasks, tags)
38
+ 2. **20240730075425_init_triggers.sql** - Sets up user sync triggers between auth.users and sales table
39
+ 3. **20240806124555_task_sales_id.sql** - Adds sales_id to tasks table
40
+ 4. **20240807082449_remove-aquisition.sql** - Removes deprecated acquisition field
41
+ 5. **20240808141826_init_state_configure.sql** - Creates init_state table for tracking initialization
42
+ 6. **20240813084010_tags_policy.sql** - Adds RLS policies for tags table
43
+ 7. **20241104153231_sales_policies.sql** - Adds RLS policies for sales table
44
+ 8. **20250109152531_email_jsonb.sql** - Migrates email to JSONB format for multiple emails
45
+ 9. **20250113132531_phone_jsonb.sql** - Migrates phone to JSONB format for multiple phones
46
+ 10. **20251204172855_merge_contacts_function.sql** - Adds contact merging functionality
47
+ 11. **20251204201317_drop_merge_contacts_function.sql** - Refactors merge function
48
+
49
+ ## What Gets Created
50
+
51
+ After running migrations, your database will have:
52
+
53
+ ### Tables
54
+ - `contacts` - Contact information with JSONB email/phone support
55
+ - `companies` - Company records with logo support
56
+ - `deals` - Deal pipeline with stages and amounts
57
+ - `contactNotes` - Notes attached to contacts
58
+ - `dealNotes` - Notes attached to deals
59
+ - `tasks` - Task management
60
+ - `sales` - CRM users (synced with auth.users)
61
+ - `tags` - Tagging system
62
+ - `init_state` - Initialization tracking
63
+
64
+ ### Views
65
+ - `contacts_summary` - Aggregated contact data with task counts
66
+ - `companies_summary` - Aggregated company data
67
+
68
+ ### Functions
69
+ - `handle_new_user()` - Auto-creates sales record when user signs up
70
+ - `handle_update_user()` - Syncs user metadata updates
71
+ - Edge functions for user management, email processing, contact merging
72
+
73
+ ### Row Level Security (RLS)
74
+ All tables have RLS enabled with policies that:
75
+ - Currently use permissive policies (`using (true)`) for all authenticated users
76
+ - Track ownership via `sales_id` foreign keys
77
+ - Can be made restrictive for data isolation (see migration files for examples)
78
+
79
+ ## Regenerating setup.sql
80
+
81
+ If you modify any migration files, regenerate the combined setup.sql:
82
+
83
+ ```bash
84
+ npm run setup:gen
85
+ ```
86
+
87
+ ## Troubleshooting
88
+
89
+ If migrations fail:
90
+ 1. Check that your Supabase project is active and accessible
91
+ 2. Ensure you have sufficient permissions (project owner)
92
+ 3. Try running migrations one by one to identify the problematic migration
93
+ 4. Check Supabase logs for detailed error messages
94
+
95
+ For help, see:
96
+ - [RealTimeX CRM Documentation](https://github.com/therealtimex/realtimex-crm#readme)
97
+ - [Supabase CLI Documentation](https://supabase.com/docs/guides/cli)
98
+ - [Report an Issue](https://github.com/therealtimex/realtimex-crm/issues)