build nocod now inputs the new urls to the .env

This commit is contained in:
admin 2025-08-10 17:08:44 -06:00
parent 35a6d55ffe
commit 8c03b321fc

View File

@ -416,6 +416,31 @@ create_login_table() {
"uidt": "Checkbox", "uidt": "Checkbox",
"rqd": false "rqd": false
}, },
{
"column_name": "UserType",
"title": "User Type",
"uidt": "SingleSelect",
"rqd": false,
"colOptions": {
"options": [
{"title": "admin", "color": "#FF6B6B"},
{"title": "user", "color": "#4ECDC4"},
{"title": "temp", "color": "#FFE66D"}
]
}
},
{
"column_name": "ExpiresAt",
"title": "Expires At",
"uidt": "DateTime",
"rqd": false
},
{
"column_name": "ExpireDays",
"title": "Expire Days",
"uidt": "Number",
"rqd": false
},
{ {
"column_name": "created_at", "column_name": "created_at",
"title": "Created At", "title": "Created At",
@ -880,74 +905,60 @@ create_default_start_location() {
make_api_call "POST" "/tables/$settings_table_id/records" "$start_location_data" "Creating default settings row" "v2" make_api_call "POST" "/tables/$settings_table_id/records" "$start_location_data" "Creating default settings row" "v2"
} }
# Function to create sample cuts data # Function to update .env file with new table URLs
create_default_cuts() { update_env_file() {
local base_id=$1 local base_id=$1
local cuts_table_id=$2 local locations_table_id=$2
local login_table_id=$3
local settings_table_id=$4
local shifts_table_id=$5
local shift_signups_table_id=$6
local cuts_table_id=$7
print_status "Creating sample cuts data..." print_status "Updating .env file with new table URLs..."
# Sample cut 1: Downtown Area (Public) # Create backup of current .env file
local cut1_geojson='{"type":"Polygon","coordinates":[[[-113.52,53.54],[-113.48,53.54],[-113.48,53.56],[-113.52,53.56],[-113.52,53.54]]]}' if [ -f ".env" ]; then
local cut1_bounds='{"north":53.56,"south":53.54,"east":-113.48,"west":-113.52}' cp ".env" ".env.backup.$(date +%Y%m%d_%H%M%S)"
print_success "Backed up current .env file"
fi
local cut1_data='{ # Construct the new URLs
"name": "Downtown Core", local new_locations_url="${BASE_URL}/dashboard/#/nc/${base_id}/${locations_table_id}"
"description": "Main downtown business district area for canvassing", local new_login_url="${BASE_URL}/dashboard/#/nc/${base_id}/${login_table_id}"
"color": "#e74c3c", local new_settings_url="${BASE_URL}/dashboard/#/nc/${base_id}/${settings_table_id}"
"opacity": 0.4, local new_shifts_url="${BASE_URL}/dashboard/#/nc/${base_id}/${shifts_table_id}"
"category": "District", local new_shift_signups_url="${BASE_URL}/dashboard/#/nc/${base_id}/${shift_signups_table_id}"
"is_public": 1, local new_cuts_url="${BASE_URL}/dashboard/#/nc/${base_id}/${cuts_table_id}"
"is_official": 1,
"geojson": "'"$cut1_geojson"'",
"bounds": "'"$cut1_bounds"'",
"created_by": "system",
"created_at": "'"$(date -u +"%Y-%m-%d %H:%M:%S")"'"
}'
make_api_call "POST" "/tables/$cuts_table_id/records" "$cut1_data" "Creating sample cut 1" "v2" print_status "Updating URLs in .env file..."
# Sample cut 2: Residential Area (Public) # Update each URL in the .env file
local cut2_geojson='{"type":"Polygon","coordinates":[[[-113.55,53.50],[-113.50,53.50],[-113.50,53.53],[-113.55,53.53],[-113.55,53.50]]]}' if [ -f ".env" ]; then
local cut2_bounds='{"north":53.53,"south":53.50,"east":-113.50,"west":-113.55}' # Use sed to update each line, creating a temporary file
sed -i.tmp "s|^NOCODB_VIEW_URL=.*|NOCODB_VIEW_URL=${new_locations_url}|" .env
local cut2_data='{ sed -i.tmp "s|^NOCODB_LOGIN_SHEET=.*|NOCODB_LOGIN_SHEET=${new_login_url}|" .env
"name": "River Valley Neighborhoods", sed -i.tmp "s|^NOCODB_SETTINGS_SHEET=.*|NOCODB_SETTINGS_SHEET=${new_settings_url}|" .env
"description": "Residential area near the river valley", sed -i.tmp "s|^NOCODB_SHIFTS_SHEET=.*|NOCODB_SHIFTS_SHEET=${new_shifts_url}|" .env
"color": "#3498db", sed -i.tmp "s|^NOCODB_SHIFT_SIGNUPS_SHEET=.*|NOCODB_SHIFT_SIGNUPS_SHEET=${new_shift_signups_url}|" .env
"opacity": 0.3, sed -i.tmp "s|^NOCODB_CUTS_SHEET=.*|NOCODB_CUTS_SHEET=${new_cuts_url}|" .env
"category": "Neighborhood",
"is_public": 1, # Remove the temporary file created by sed
"is_official": 0, rm -f .env.tmp
"geojson": "'"$cut2_geojson"'",
"bounds": "'"$cut2_bounds"'", print_success "Updated .env file with new table URLs"
"created_by": "system", print_status ""
"created_at": "'"$(date -u +"%Y-%m-%d %H:%M:%S")"'" print_status "New URLs set in .env file:"
}' print_status " NOCODB_VIEW_URL=${new_locations_url}"
print_status " NOCODB_LOGIN_SHEET=${new_login_url}"
make_api_call "POST" "/tables/$cuts_table_id/records" "$cut2_data" "Creating sample cut 2" "v2" print_status " NOCODB_SETTINGS_SHEET=${new_settings_url}"
print_status " NOCODB_SHIFTS_SHEET=${new_shifts_url}"
# Sample cut 3: Private Admin Cut (Not Public) print_status " NOCODB_SHIFT_SIGNUPS_SHEET=${new_shift_signups_url}"
local cut3_geojson='{"type":"Polygon","coordinates":[[[-113.45,53.57],[-113.40,53.57],[-113.40,53.60],[-113.45,53.60],[-113.45,53.57]]]}' print_status " NOCODB_CUTS_SHEET=${new_cuts_url}"
local cut3_bounds='{"north":53.60,"south":53.57,"east":-113.40,"west":-113.45}' else
print_error "Could not find .env file to update"
local cut3_data='{ return 1
"name": "Admin Only Area", fi
"description": "Private administrative boundary for internal use",
"color": "#9b59b6",
"opacity": 0.5,
"category": "Custom",
"is_public": 0,
"is_official": 0,
"geojson": "'"$cut3_geojson"'",
"bounds": "'"$cut3_bounds"'",
"created_by": "system",
"created_at": "'"$(date -u +"%Y-%m-%d %H:%M:%S")"'"
}'
make_api_call "POST" "/tables/$cuts_table_id/records" "$cut3_data" "Creating sample cut 3" "v2"
print_success "Created 3 sample cuts (2 public, 1 private)"
} }
# Main execution # Main execution
@ -1000,8 +1011,8 @@ main() {
# Create default settings row (includes both start location and walk sheet config) # Create default settings row (includes both start location and walk sheet config)
create_default_start_location "$BASE_ID" "$SETTINGS_TABLE_ID" create_default_start_location "$BASE_ID" "$SETTINGS_TABLE_ID"
# Create sample cuts data for testing # Update .env file with new table URLs
create_default_cuts "$BASE_ID" "$CUTS_TABLE_ID" update_env_file "$BASE_ID" "$LOCATIONS_TABLE_ID" "$LOGIN_TABLE_ID" "$SETTINGS_TABLE_ID" "$SHIFTS_TABLE_ID" "$SHIFT_SIGNUPS_TABLE_ID" "$CUTS_TABLE_ID"
print_status "================================" print_status "================================"
print_success "NocoDB Auto-Setup completed successfully!" print_success "NocoDB Auto-Setup completed successfully!"
@ -1011,21 +1022,15 @@ main() {
print_status "" print_status ""
print_status "Next steps:" print_status "Next steps:"
print_status "1. Login to your NocoDB instance at: $BASE_URL" print_status "1. Login to your NocoDB instance at: $BASE_URL"
print_status "2. Find your new base and navigate to each table" print_status "2. Your .env file has been automatically updated with the new table URLs!"
print_status "3. For each table, copy the view URL and update your .env file:" print_status "3. The default admin user is: admin@thebunkerops.ca with password: admin123"
print_status " - NOCODB_VIEW_URL (for locations table)" print_status "4. IMPORTANT: Change the default password after first login!"
print_status " - NOCODB_LOGIN_SHEET (for login table)" print_status "5. Start adding your location data!"
print_status " - NOCODB_SETTINGS_SHEET (for settings table)"
print_status " - NOCODB_SHIFTS_SHEET (for shifts table)"
print_status " - NOCODB_SHIFT_SIGNUPS_SHEET (for shift signups table)"
print_status " - NOCODB_CUTS_SHEET (for cuts table)"
print_status "4. The default admin user is: admin@thebunkerops.ca with password: admin123"
print_status "5. IMPORTANT: Change the default password after first login!"
print_status "6. Start adding your location data!"
print_warning "" print_warning ""
print_warning "IMPORTANT: This script created a NEW base. Your existing data was NOT modified." print_warning "IMPORTANT: This script created a NEW base. Your existing data was NOT modified."
print_warning "Please update your .env file with the new table URLs from the newly created base." print_warning "Your .env file has been automatically updated with the new table URLs."
print_warning "A backup of your previous .env file was created with a timestamp."
print_warning "SECURITY: Change the default admin password immediately after first login!" print_warning "SECURITY: Change the default admin password immediately after first login!"
} }