-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup-nocodb.sh
executable file
·164 lines (148 loc) · 6.3 KB
/
setup-nocodb.sh
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# Configuration
NOCODB_URL="http://localhost:8080"
AUTH_TOKEN="" # Will be set after sign-up/login
BASE_ID="pvusi5vh1eqgt3i"
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Function to make API calls
api_call() {
local method=$1
local endpoint=$2
local data=$3
if [ -n "$data" ]; then
curl -s -X "$method" \
"$NOCODB_URL/api/v1/$endpoint" \
-H "Content-Type: application/json" \
-H "xc-auth: $AUTH_TOKEN" \
-d "$data"
else
curl -s -X "$method" \
"$NOCODB_URL/api/v1/$endpoint" \
-H "Content-Type: application/json" \
-H "xc-auth: $AUTH_TOKEN"
fi
}
# Function to create a table
create_table() {
local table_name=$1
local columns=$2
echo "Creating table: $table_name"
api_call "POST" "db/meta/projects/$BASE_ID/tables" "{
\"table_name\": \"$table_name\",
\"title\": \"$table_name\",
\"columns\": $columns
}"
}
# Wait for NocoDB to be ready
echo "Waiting for NocoDB to be ready..."
while ! curl -s "$NOCODB_URL/api/v1/health" > /dev/null; do
sleep 2
done
# Login to get auth token
echo "Logging in..."
LOGIN_RESPONSE=$(curl -s -X "POST" "$NOCODB_URL/api/v1/auth/user/signin" \
-H "Content-Type: application/json" \
-d "{
\"email\": \"[email protected]\",
\"password\": \"Ezulove@21\"
}")
AUTH_TOKEN=$(echo $LOGIN_RESPONSE | grep -o '"token":"[^"]*' | cut -d'"' -f4)
if [ -z "$AUTH_TOKEN" ]; then
echo -e "${RED}Failed to get auth token${NC}"
exit 1
fi
# Create video_templates table
VIDEO_TEMPLATES_COLUMNS='[
{"column_name": "id", "title": "id", "uidt": "ID", "pk": true, "ai": false},
{"column_name": "name", "title": "name", "uidt": "SingleLineText"},
{"column_name": "description", "title": "description", "uidt": "LongText"},
{"column_name": "duration", "title": "duration", "uidt": "Number"},
{"column_name": "resolution_width", "title": "resolution_width", "uidt": "Number", "default": "1080"},
{"column_name": "resolution_height", "title": "resolution_height", "uidt": "Number", "default": "1920"},
{"column_name": "components", "title": "components", "uidt": "JSON"},
{"column_name": "created_at", "title": "created_at", "uidt": "DateTime", "default": "now()"},
{"column_name": "updated_at", "title": "updated_at", "uidt": "DateTime", "default": "now()"}
]'
create_table "video_templates" "$VIDEO_TEMPLATES_COLUMNS"
# Create content table
CONTENT_COLUMNS='[
{"column_name": "id", "title": "id", "uidt": "ID", "pk": true, "ai": false},
{"column_name": "title", "title": "title", "uidt": "SingleLineText"},
{"column_name": "description", "title": "description", "uidt": "LongText"},
{"column_name": "template_id", "title": "template_id", "uidt": "LinkToAnotherRecord", "options": {
"foreignTableName": "video_templates",
"type": "belongsTo"
}},
{"column_name": "content_data", "title": "content_data", "uidt": "JSON"},
{"column_name": "status", "title": "status", "uidt": "SingleSelect", "dtxp": "draft,processing,completed,failed"},
{"column_name": "openai_enhanced", "title": "openai_enhanced", "uidt": "Checkbox"},
{"column_name": "created_at", "title": "created_at", "uidt": "DateTime", "default": "now()"},
{"column_name": "updated_at", "title": "updated_at", "uidt": "DateTime", "default": "now()"}
]'
create_table "content" "$CONTENT_COLUMNS"
# Create assets table
ASSETS_COLUMNS='[
{"column_name": "id", "title": "id", "uidt": "ID", "pk": true, "ai": false},
{"column_name": "name", "title": "name", "uidt": "SingleLineText"},
{"column_name": "type", "title": "type", "uidt": "SingleSelect", "dtxp": "image,audio,video"},
{"column_name": "s3_key", "title": "s3_key", "uidt": "SingleLineText"},
{"column_name": "content_type", "title": "content_type", "uidt": "SingleLineText"},
{"column_name": "file_size", "title": "file_size", "uidt": "Number"},
{"column_name": "metadata", "title": "metadata", "uidt": "JSON"},
{"column_name": "created_at", "title": "created_at", "uidt": "DateTime", "default": "now()"}
]'
create_table "assets" "$ASSETS_COLUMNS"
# Create generated_videos table
GENERATED_VIDEOS_COLUMNS='[
{"column_name": "id", "title": "id", "uidt": "ID", "pk": true, "ai": false},
{"column_name": "content_id", "title": "content_id", "uidt": "LinkToAnotherRecord", "options": {
"foreignTableName": "content",
"type": "belongsTo"
}},
{"column_name": "template_id", "title": "template_id", "uidt": "LinkToAnotherRecord", "options": {
"foreignTableName": "video_templates",
"type": "belongsTo"
}},
{"column_name": "s3_key", "title": "s3_key", "uidt": "SingleLineText"},
{"column_name": "duration", "title": "duration", "uidt": "Number"},
{"column_name": "file_size", "title": "file_size", "uidt": "Number"},
{"column_name": "status", "title": "status", "uidt": "SingleSelect", "dtxp": "pending,processing,completed,failed"},
{"column_name": "render_metadata", "title": "render_metadata", "uidt": "JSON"},
{"column_name": "created_at", "title": "created_at", "uidt": "DateTime", "default": "now()"},
{"column_name": "completed_at", "title": "completed_at", "uidt": "DateTime"}
]'
create_table "generated_videos" "$GENERATED_VIDEOS_COLUMNS"
# Insert sample template
echo "Inserting sample template..."
api_call "POST" "db/data/v1/$BASE_ID/video_templates/records" "{
\"name\": \"Basic TikTok Template\",
\"description\": \"A simple template with text overlay and background image\",
\"duration\": 30,
\"components\": {
\"layout\": \"vertical\",
\"scenes\": [
{
\"duration\": 30,
\"components\": [
{
\"type\": \"background\",
\"assetId\": null
},
{
\"type\": \"text\",
\"position\": \"center\",
\"style\": {
\"fontSize\": 48,
\"fontWeight\": \"bold\",
\"color\": \"#ffffff\"
}
}
]
}
]
}
}"
echo -e "${GREEN}NocoDB setup completed successfully!${NC}"