-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_alembic.sh
More file actions
66 lines (60 loc) · 1.67 KB
/
Copy pathrun_alembic.sh
File metadata and controls
66 lines (60 loc) · 1.67 KB
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
#!/bin/bash
# Help function
show_help() {
echo "Usage: $0 [OPTIONS]"
echo "Run Alembic migrations with optional skip flags"
echo ""
echo "Options:"
echo " -r, --skip-revision Skip the revision generation step"
echo " -u, --skip-upgrade Skip the upgrade head step"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Run both revision and upgrade"
echo " $0 -r # Skip revision, only run upgrade"
echo " $0 -u # Skip upgrade, only run revision"
echo " $0 -r -u # Skip both (no operation)"
}
# Initialize flags
SKIP_REVISION=false
SKIP_UPGRADE=false
# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-r|--skip-revision)
SKIP_REVISION=true
shift
;;
-u|--skip-upgrade)
SKIP_UPGRADE=true
shift
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done
# shellcheck disable=SC2164
cd /app
# Run revision generation if not skipped
if [ "$SKIP_REVISION" = false ]; then
# shellcheck disable=SC2034
current_date=$(date +"%Y-%m-%d %H:%M:%S")
echo "Generating Alembic revision..."
alembic revision --autogenerate -m "revision generated on ${current_date}"
else
echo "Skipping revision generation"
fi
# Run upgrade if not skipped
if [ "$SKIP_UPGRADE" = false ]; then
echo "Upgrading database to head..."
alembic upgrade head
else
echo "Skipping database upgrade"
fi