From 8c03b321fc312c420260c17349e4a7029f2c3898 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 10 Aug 2025 17:08:44 -0600 Subject: [PATCH] build nocod now inputs the new urls to the .env --- map/build-nocodb.sh | 157 +++++++++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 76 deletions(-) diff --git a/map/build-nocodb.sh b/map/build-nocodb.sh index c50b8af..354ea7b 100755 --- a/map/build-nocodb.sh +++ b/map/build-nocodb.sh @@ -416,6 +416,31 @@ create_login_table() { "uidt": "Checkbox", "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", "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" } -# Function to create sample cuts data -create_default_cuts() { +# Function to update .env file with new table URLs +update_env_file() { 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) - 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]]]}' - local cut1_bounds='{"north":53.56,"south":53.54,"east":-113.48,"west":-113.52}' + # Create backup of current .env file + if [ -f ".env" ]; then + cp ".env" ".env.backup.$(date +%Y%m%d_%H%M%S)" + print_success "Backed up current .env file" + fi - local cut1_data='{ - "name": "Downtown Core", - "description": "Main downtown business district area for canvassing", - "color": "#e74c3c", - "opacity": 0.4, - "category": "District", - "is_public": 1, - "is_official": 1, - "geojson": "'"$cut1_geojson"'", - "bounds": "'"$cut1_bounds"'", - "created_by": "system", - "created_at": "'"$(date -u +"%Y-%m-%d %H:%M:%S")"'" - }' + # Construct the new URLs + local new_locations_url="${BASE_URL}/dashboard/#/nc/${base_id}/${locations_table_id}" + local new_login_url="${BASE_URL}/dashboard/#/nc/${base_id}/${login_table_id}" + local new_settings_url="${BASE_URL}/dashboard/#/nc/${base_id}/${settings_table_id}" + local new_shifts_url="${BASE_URL}/dashboard/#/nc/${base_id}/${shifts_table_id}" + local new_shift_signups_url="${BASE_URL}/dashboard/#/nc/${base_id}/${shift_signups_table_id}" + local new_cuts_url="${BASE_URL}/dashboard/#/nc/${base_id}/${cuts_table_id}" - 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) - 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]]]}' - local cut2_bounds='{"north":53.53,"south":53.50,"east":-113.50,"west":-113.55}' - - local cut2_data='{ - "name": "River Valley Neighborhoods", - "description": "Residential area near the river valley", - "color": "#3498db", - "opacity": 0.3, - "category": "Neighborhood", - "is_public": 1, - "is_official": 0, - "geojson": "'"$cut2_geojson"'", - "bounds": "'"$cut2_bounds"'", - "created_by": "system", - "created_at": "'"$(date -u +"%Y-%m-%d %H:%M:%S")"'" - }' - - make_api_call "POST" "/tables/$cuts_table_id/records" "$cut2_data" "Creating sample cut 2" "v2" - - # Sample cut 3: Private Admin Cut (Not Public) - 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]]]}' - local cut3_bounds='{"north":53.60,"south":53.57,"east":-113.40,"west":-113.45}' - - local cut3_data='{ - "name": "Admin Only Area", - "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)" + # Update each URL in the .env file + if [ -f ".env" ]; then + # Use sed to update each line, creating a temporary file + sed -i.tmp "s|^NOCODB_VIEW_URL=.*|NOCODB_VIEW_URL=${new_locations_url}|" .env + sed -i.tmp "s|^NOCODB_LOGIN_SHEET=.*|NOCODB_LOGIN_SHEET=${new_login_url}|" .env + sed -i.tmp "s|^NOCODB_SETTINGS_SHEET=.*|NOCODB_SETTINGS_SHEET=${new_settings_url}|" .env + sed -i.tmp "s|^NOCODB_SHIFTS_SHEET=.*|NOCODB_SHIFTS_SHEET=${new_shifts_url}|" .env + sed -i.tmp "s|^NOCODB_SHIFT_SIGNUPS_SHEET=.*|NOCODB_SHIFT_SIGNUPS_SHEET=${new_shift_signups_url}|" .env + sed -i.tmp "s|^NOCODB_CUTS_SHEET=.*|NOCODB_CUTS_SHEET=${new_cuts_url}|" .env + + # Remove the temporary file created by sed + rm -f .env.tmp + + print_success "Updated .env file with new table URLs" + print_status "" + print_status "New URLs set in .env file:" + print_status " NOCODB_VIEW_URL=${new_locations_url}" + print_status " NOCODB_LOGIN_SHEET=${new_login_url}" + print_status " NOCODB_SETTINGS_SHEET=${new_settings_url}" + print_status " NOCODB_SHIFTS_SHEET=${new_shifts_url}" + print_status " NOCODB_SHIFT_SIGNUPS_SHEET=${new_shift_signups_url}" + print_status " NOCODB_CUTS_SHEET=${new_cuts_url}" + else + print_error "Could not find .env file to update" + return 1 + fi } # Main execution @@ -1000,8 +1011,8 @@ main() { # Create default settings row (includes both start location and walk sheet config) create_default_start_location "$BASE_ID" "$SETTINGS_TABLE_ID" - # Create sample cuts data for testing - create_default_cuts "$BASE_ID" "$CUTS_TABLE_ID" + # Update .env file with new table URLs + 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_success "NocoDB Auto-Setup completed successfully!" @@ -1011,21 +1022,15 @@ main() { print_status "" print_status "Next steps:" 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 "3. For each table, copy the view URL and update your .env file:" - print_status " - NOCODB_VIEW_URL (for locations table)" - print_status " - NOCODB_LOGIN_SHEET (for login table)" - 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_status "2. Your .env file has been automatically updated with the new table URLs!" + print_status "3. The default admin user is: admin@thebunkerops.ca with password: admin123" + print_status "4. IMPORTANT: Change the default password after first login!" + print_status "5. Start adding your location data!" print_warning "" 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!" }