Skip to content

Commit

Permalink
chore(feat): add fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ndu committed Dec 27, 2024
1 parent 91c8b4f commit e059b8e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dumps/
.env
.env.local
.env.production
.env.backup.*
__pycache__/
test.py
test.json
Expand All @@ -18,6 +19,4 @@ test.rest
db.sqlite3
old-backup-db.sqlite3
dump.rdp
client/

switch-env.sh
client/
2 changes: 1 addition & 1 deletion server/core/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
load_dotenv()

# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', os.getenv('DJANGO_SETTINGS_MODULE', 'core.config.local'))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', os.getenv('DJANGO_SETTINGS_MODULE', 'core.config.production'))

app = Celery('core')

Expand Down
1 change: 1 addition & 0 deletions server/core/config/local.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .base import *
from decouple import config

# Development-specific settings
DEBUG = True
Expand Down
46 changes: 46 additions & 0 deletions switch-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

# Function to validate environment name
validate_env() {
if [[ ! "$1" =~ ^(local|production)$ ]]; then
echo "Error: Invalid environment. Please specify 'local' or 'production'."
exit 1
fi
}

# Function to check file existence
check_file() {
if [[ ! -f "$1" ]]; then
echo "Error: $1 does not exist."
exit 1
fi
}

# Main script
if [[ -z "$1" ]]; then
echo "Error: No environment specified. Please specify 'local' or 'prod'."
exit 1
fi

validate_env "$1"

source_file=".env.$1"
check_file "$source_file"

# Backup existing .env if it exists
if [[ -f .env ]]; then
backup_file=".env.backup.$(date +%Y%m%d_%H%M%S)"
cp .env "$backup_file"
echo "Existing .env backed up to $backup_file"
fi

# Copy the specified environment file to .env
cp "$source_file" .env

# Verify the copy was successful
if [[ $? -eq 0 ]]; then
echo "Successfully switched to $1 environment."
else
echo "Error: Failed to switch environment."
exit 1
fi

0 comments on commit e059b8e

Please sign in to comment.