Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	docker-compose.yml
#	justfile
#	src/schemas.py
  • Loading branch information
zhanymkanov committed Jun 12, 2024
2 parents dfc739b + 9d548b2 commit 2e450e7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ ENVIRONMENT=LOCAL

CORS_HEADERS=["*"]
CORS_ORIGINS=["http://localhost:3000"]


# postgres variables, must be the same as in DATABASE_URL
POSTGRES_USER=app
POSTGRES_PASSWORD=app
POSTGRES_HOST=app_db
POSTGRES_PORT=5432
POSTGRES_DB=app
17 changes: 17 additions & 0 deletions scripts/postgres/backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh -e

echo "Backup process started."

export POSTGRES_USER="${POSTGRES_USER}"

# Save the current date in YYYY-MM-DD format to a variable
current_datetime=$(date +%Y-%m-%d-%H%M%S)

backup_directory="/backups"
backup_filename="${backup_directory}/backup-${current_datetime}.dump.gz"

# Run pg_dump and compress its output, then save to /backups with the current date in the filename
pg_dump -Fc app -U "$POSTGRES_USER" | gzip > "$backup_filename"


echo "Backup has been created and saved to ${backup_filename}"
38 changes: 38 additions & 0 deletions scripts/postgres/restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh -e

# The directory where backups are stored
BACKUP_DIRECTORY="/backups"

# Check if a file name was provided as a parameter
if [ $# -eq 0 ]; then
echo "No file name provided. Please provide a file name to check."
exit 1
fi

# The file name is taken from the first argument provided to the script
file_name="$1"

# Full path to the file
full_file_path="${BACKUP_DIRECTORY}/${file_name}"

# Check if the file exists
if [ -f "$full_file_path" ]; then
echo "File ${file_name} exists."
else
echo "File ${file_name} does not exist."
exit 1
fi

export POSTGRES_USER="${POSTGRES_USER}"
export POSTGRES_DB="${POSTGRES_DB}"

echo "Dropping the database..."
dropdb "$POSTGRES_DB" -U "$POSTGRES_USER"

echo "Creating a new database..."
createdb "$POSTGRES_DB" --owner="$POSTGRES_USER" -U "$POSTGRES_USER"

echo "Applying the backup to the new database..."
gunzip -c "${full_file_path}" | pg_restore -U "$POSTGRES_USER" -d "$POSTGRES_DB"

echo "Backup applied successfully."
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

class Environment(str, Enum):
LOCAL = "LOCAL"
STAGING = "STAGING"
TESTING = "TESTING"
STAGING = "STAGING"
PRODUCTION = "PRODUCTION"

@property
Expand Down
1 change: 1 addition & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import string

logger = logging.getLogger(__name__)

ALPHA_NUM = string.ascii_letters + string.digits


Expand Down

0 comments on commit 2e450e7

Please sign in to comment.