Spaces:
Runtime error
Runtime error
updated SQL readme and added install bash
Browse files- sql/install_sql.sh +48 -0
- sql/readme.md +142 -0
sql/install_sql.sh
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Load environment variables
|
4 |
+
source .env
|
5 |
+
|
6 |
+
# Check if environment variables are set
|
7 |
+
if [ -z "$SUPABASE_URL" ] || [ -z "$SUPABASE_DB" ] || [ -z "$SUPABASE_USER" ] || [ -z "$SUPABASE_PASSWORD" ]; then
|
8 |
+
echo "Please set the SUPABASE_URL, SUPABASE_DB, SUPABASE_USER, and SUPABASE_PASSWORD environment variables in the .env file."
|
9 |
+
exit 1
|
10 |
+
fi
|
11 |
+
|
12 |
+
# Function to execute a SQL file
|
13 |
+
execute_sql() {
|
14 |
+
local file=$1
|
15 |
+
echo "Executing $file..."
|
16 |
+
PGPASSWORD=$SUPABASE_PASSWORD psql -h $SUPABASE_URL -d $SUPABASE_DB -U $SUPABASE_USER -f $file
|
17 |
+
if [ $? -eq 0 ]; then
|
18 |
+
echo "$file executed successfully."
|
19 |
+
else
|
20 |
+
echo "Error executing $file."
|
21 |
+
exit 1
|
22 |
+
fi
|
23 |
+
}
|
24 |
+
|
25 |
+
# List of SQL files to be executed
|
26 |
+
sql_files=(
|
27 |
+
"agent_data.sql"
|
28 |
+
"agent_interaction.sql"
|
29 |
+
"analytics_reporting.sql"
|
30 |
+
"chat_history_agent_details.sql"
|
31 |
+
"command_control.sql"
|
32 |
+
"documentation.sql"
|
33 |
+
"governance.sql"
|
34 |
+
"system_settings.sql"
|
35 |
+
"users_agents.sql"
|
36 |
+
)
|
37 |
+
|
38 |
+
# Execute each SQL file
|
39 |
+
for sql_file in "${sql_files[@]}"; do
|
40 |
+
if [ -f "$sql_file" ]; then
|
41 |
+
execute_sql "$sql_file"
|
42 |
+
else
|
43 |
+
echo "File $sql_file does not exist."
|
44 |
+
exit 1
|
45 |
+
fi
|
46 |
+
done
|
47 |
+
|
48 |
+
echo "All SQL files executed successfully."
|
sql/readme.md
CHANGED
@@ -211,3 +211,145 @@ CREATE INDEX idx_users_agents_tenant_id ON users_agents(tenant_id);
|
|
211 |
```sh
|
212 |
psql -h your-supabase-url -U your-username -d your-database -f path/to/sql_script.sql
|
213 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
```sh
|
212 |
psql -h your-supabase-url -U your-username -d your-database -f path/to/sql_script.sql
|
213 |
```
|
214 |
+
|
215 |
+
# Setting Up Supabase and Installing SQL Files
|
216 |
+
|
217 |
+
## Overview
|
218 |
+
This guide will walk you through setting up Supabase, configuring your environment, and running a bash script to install various SQL files into your Supabase database.
|
219 |
+
|
220 |
+
## Prerequisites
|
221 |
+
- A Supabase account and project
|
222 |
+
- `psql` command-line tool installed
|
223 |
+
- A terminal or command-line interface
|
224 |
+
|
225 |
+
## Step 1: Set Up Supabase
|
226 |
+
|
227 |
+
### 1.1 Create a Supabase Account
|
228 |
+
1. Go to [Supabase](https://supabase.io/).
|
229 |
+
2. Sign up for a free account and log in.
|
230 |
+
|
231 |
+
### 1.2 Create a New Project
|
232 |
+
1. Once logged in, click on "New Project".
|
233 |
+
2. Fill in the project details:
|
234 |
+
- **Name**: Choose a name for your project.
|
235 |
+
- **Database Password**: Set a strong password.
|
236 |
+
- **Region**: Select a region close to you.
|
237 |
+
3. Click "Create new project".
|
238 |
+
|
239 |
+
### 1.3 Get Database Connection Details
|
240 |
+
1. After the project is created, navigate to the "Settings" > "Database" tab.
|
241 |
+
2. Note down the following details:
|
242 |
+
- **Database URL**
|
243 |
+
- **Database name**
|
244 |
+
- **Database user**
|
245 |
+
- **Database password**
|
246 |
+
|
247 |
+
## Step 2: Install `psql`
|
248 |
+
|
249 |
+
### 2.1 Install on macOS
|
250 |
+
```sh
|
251 |
+
brew install postgresql
|
252 |
+
```
|
253 |
+
|
254 |
+
### 2.2 Install on Linux (Debian-based)
|
255 |
+
```sh
|
256 |
+
sudo apt update
|
257 |
+
sudo apt install postgresql-client
|
258 |
+
```
|
259 |
+
|
260 |
+
### 2.3 Install on Windows
|
261 |
+
Download and install PostgreSQL from the [official website](https://www.postgresql.org/download/), ensuring `psql` is included in the installation.
|
262 |
+
|
263 |
+
## Step 3: Prepare the SQL Files
|
264 |
+
|
265 |
+
Ensure that you have the following SQL files in your project directory:
|
266 |
+
- `agent_data.sql`
|
267 |
+
- `agent_interaction.sql`
|
268 |
+
- `analytics_reporting.sql`
|
269 |
+
- `chat_history_agent_details.sql`
|
270 |
+
- `command_control.sql`
|
271 |
+
- `documentation.sql`
|
272 |
+
- `governance.sql`
|
273 |
+
- `system_settings.sql`
|
274 |
+
- `users_agents.sql`
|
275 |
+
|
276 |
+
## Step 4: Create the `.env` File
|
277 |
+
|
278 |
+
Create a `.env` file in your project directory and add the following content, replacing the placeholders with your actual Supabase details:
|
279 |
+
|
280 |
+
```env
|
281 |
+
SUPABASE_URL=your-supabase-url
|
282 |
+
SUPABASE_DB=your-database-name
|
283 |
+
SUPABASE_USER=your-username
|
284 |
+
SUPABASE_PASSWORD=your-password
|
285 |
+
```
|
286 |
+
|
287 |
+
## Step 5: Create the Installation Script
|
288 |
+
|
289 |
+
Create a file named `install_sql.sh` in your project directory and add the following content:
|
290 |
+
|
291 |
+
```bash
|
292 |
+
#!/bin/bash
|
293 |
+
|
294 |
+
# Load environment variables
|
295 |
+
source .env
|
296 |
+
|
297 |
+
# Check if environment variables are set
|
298 |
+
if [ -z "$SUPABASE_URL" ] || [ -z "$SUPABASE_DB" ] || [ -z "$SUPABASE_USER" ] || [ -z "$SUPABASE_PASSWORD" ]; then
|
299 |
+
echo "Please set the SUPABASE_URL, SUPABASE_DB, SUPABASE_USER, and SUPABASE_PASSWORD environment variables in the .env file."
|
300 |
+
exit 1
|
301 |
+
fi
|
302 |
+
|
303 |
+
# Function to execute a SQL file
|
304 |
+
execute_sql() {
|
305 |
+
local file=$1
|
306 |
+
echo "Executing $file..."
|
307 |
+
PGPASSWORD=$SUPABASE_PASSWORD psql -h $SUPABASE_URL -d $SUPABASE_DB -U $SUPABASE_USER -f $file
|
308 |
+
if [ $? -eq 0 ]; then
|
309 |
+
echo "$file executed successfully."
|
310 |
+
else
|
311 |
+
echo "Error executing $file."
|
312 |
+
exit 1
|
313 |
+
fi
|
314 |
+
}
|
315 |
+
|
316 |
+
# List of SQL files to be executed
|
317 |
+
sql_files=(
|
318 |
+
"agent_data.sql"
|
319 |
+
"agent_interaction.sql"
|
320 |
+
"analytics_reporting.sql"
|
321 |
+
"chat_history_agent_details.sql"
|
322 |
+
"command_control.sql"
|
323 |
+
"documentation.sql"
|
324 |
+
"governance.sql"
|
325 |
+
"system_settings.sql"
|
326 |
+
"users_agents.sql"
|
327 |
+
)
|
328 |
+
|
329 |
+
# Execute each SQL file
|
330 |
+
for sql_file in "${sql_files[@]}"; do
|
331 |
+
if [ -f "$sql_file" ]; then
|
332 |
+
execute_sql "$sql_file"
|
333 |
+
else
|
334 |
+
echo "File $sql_file does not exist."
|
335 |
+
exit 1
|
336 |
+
fi
|
337 |
+
done
|
338 |
+
|
339 |
+
echo "All SQL files executed successfully."
|
340 |
+
```
|
341 |
+
|
342 |
+
## Step 6: Run the Installation Script
|
343 |
+
|
344 |
+
### 6.1 Make the Script Executable
|
345 |
+
Run the following command to make the script executable:
|
346 |
+
```sh
|
347 |
+
chmod +x install_sql.sh
|
348 |
+
```
|
349 |
+
|
350 |
+
### 6.2 Execute the Script
|
351 |
+
Run the script to install the SQL files into your Supabase database:
|
352 |
+
```sh
|
353 |
+
./install_sql.sh
|
354 |
+
```
|
355 |
+
|