@@ -223,8 +223,10 @@ clean:
223
223
# # --- Automated checks --------------------------------------------------------
224
224
smoketest :
225
225
@echo " 🚀 Running smoketest..."
226
- @./smoketest.py --verbose || { echo " ❌ Smoketest failed!" ; exit 1; }
227
- @echo " ✅ Smoketest passed!"
226
+ @bash -c ' \
227
+ ./smoketest.py --verbose || { echo " ❌ Smoketest failed!" ; exit 1; }; \
228
+ echo " ✅ Smoketest passed!" \
229
+ '
228
230
229
231
test :
230
232
@echo " 🧪 Running tests..."
@@ -1194,7 +1196,7 @@ endef
1194
1196
1195
1197
# Containerfile to use (can be overridden)
1196
1198
# CONTAINER_FILE ?= Containerfile
1197
- CONTAINER_FILE ?= $(shell [ -f "Containerfile" ] && echo "Containerfile" || echo "Dockerfile")
1199
+ CONTAINER_FILE ?= $(shell [ -f "Containerfile.lite " ] && echo "Containerfile.lite " || echo "Dockerfile")
1198
1200
1199
1201
1200
1202
# Define COMMA for the conditional Z flag
@@ -1267,6 +1269,7 @@ container-run-ssl: certs container-check-image
1267
1269
-$(CONTAINER_RUNTIME ) stop $(PROJECT_NAME ) 2> /dev/null || true
1268
1270
-$(CONTAINER_RUNTIME ) rm $(PROJECT_NAME ) 2> /dev/null || true
1269
1271
$(CONTAINER_RUNTIME ) run --name $(PROJECT_NAME ) \
1272
+ -u $(id -u ) :$(id -g ) \
1270
1273
--env-file=.env \
1271
1274
-e SSL=true \
1272
1275
-e CERT_FILE=certs/cert.pem \
@@ -1287,6 +1290,7 @@ container-run-ssl-host: certs container-check-image
1287
1290
-$(CONTAINER_RUNTIME ) stop $(PROJECT_NAME ) 2> /dev/null || true
1288
1291
-$(CONTAINER_RUNTIME ) rm $(PROJECT_NAME ) 2> /dev/null || true
1289
1292
$(CONTAINER_RUNTIME ) run --name $(PROJECT_NAME ) \
1293
+ -u $(id -u ) :$(id -g ) \
1290
1294
--network=host \
1291
1295
--env-file=.env \
1292
1296
-e SSL=true \
@@ -2775,47 +2779,112 @@ shfmt-fix: shell-linters-install ## 🎨 Auto-format *.sh in place
2775
2779
# =============================================================================
2776
2780
# help: 🛢️ ALEMBIC DATABASE MIGRATIONS
2777
2781
# help: alembic-install - Install Alembic CLI (and SQLAlchemy) in the current env
2778
- # help: db-new - Create a new migration (override with MSG="your title")
2779
- # help: db-up - Upgrade DB to the latest revision (head)
2780
- # help: db-down - Downgrade one revision (override with REV=<id|steps>)
2781
- # help: db-current - Show the current head revision for the database
2782
- # help: db-history - Show the full migration graph / history
2783
- # help: db-revision-id - Echo just the current revision id (handy for scripting)
2782
+ # help: db-init - Initialize alembic migrations
2783
+ # help: db-migrate - Create a new migration
2784
+ # help: db-upgrade - Upgrade database to latest migration
2785
+ # help: db-downgrade - Downgrade database by one revision
2786
+ # help: db-current - Show current database revision
2787
+ # help: db-history - Show migration history
2788
+ # help: db-heads - Show available heads
2789
+ # help: db-show - Show a specific revision
2790
+ # help: db-stamp - Stamp database with a specific revision
2791
+ # help: db-reset - Reset database (CAUTION: drops all data)
2792
+ # help: db-status - Show detailed database status
2793
+ # help: db-check - Check if migrations are up to date
2794
+ # help: db-fix-head - Fix multiple heads issue
2784
2795
# -----------------------------------------------------------------------------
2785
2796
2786
- # ──────────────────────────
2787
- # Internals & defaults
2788
- # ──────────────────────────
2789
- ALEMBIC ?= alembic # Override to e.g. `poetry run alembic`
2790
- MSG ?= "auto migration"
2791
- REV ?= -1 # Default: one step down; can be hash, -n, +n, etc.
2797
+ # Database migration commands
2798
+ ALEMBIC_CONFIG = mcpgateway/alembic.ini
2792
2799
2793
- .PHONY : alembic-install db-new db-up db-down db-current db-history db-revision-id
2800
+ .PHONY : alembic-install db-init db-migrate db-upgrade db-downgrade db- current db-history db-heads db-show db-stamp db-reset db-status db-check db-fix-head
2794
2801
2795
2802
alembic-install :
2796
2803
@echo " ➜ Installing Alembic ..."
2797
2804
pip install --quiet alembic sqlalchemy
2798
2805
2799
- db-new :
2800
- @echo " ➜ Generating revision: $( MSG) "
2801
- $(ALEMBIC ) -c mcpgateway/alembic.ini revision --autogenerate -m $(MSG )
2802
-
2803
- db-up :
2804
- @echo " ➜ Upgrading database to head ..."
2805
- $(ALEMBIC ) -c mcpgateway/alembic.ini upgrade head
2806
-
2807
- db-down :
2808
- @echo " ➜ Downgrading database → $( REV) ..."
2809
- $(ALEMBIC ) -c mcpgateway/alembic.ini downgrade $(REV )
2810
-
2811
- db-current :
2812
- $(ALEMBIC ) -c mcpgateway/alembic.ini current
2806
+ .PHONY : db-init
2807
+ db-init : # # Initialize alembic migrations
2808
+ @echo " 🗄️ Initializing database migrations..."
2809
+ alembic -c $(ALEMBIC_CONFIG ) init alembic
2810
+
2811
+ .PHONY : db-migrate
2812
+ db-migrate : # # Create a new migration
2813
+ @echo " �️ Creating new migration..."
2814
+ @read -p " Enter migration message: " msg; \
2815
+ alembic -c $(ALEMBIC_CONFIG ) revision --autogenerate -m " $$ msg"
2816
+
2817
+ .PHONY : db-upgrade
2818
+ db-upgrade : # # Upgrade database to latest migration
2819
+ @echo " 🗄️ Upgrading database..."
2820
+ alembic -c $(ALEMBIC_CONFIG ) upgrade head
2821
+
2822
+ .PHONY : db-downgrade
2823
+ db-downgrade : # # Downgrade database by one revision
2824
+ @echo " �️ Downgrading database..."
2825
+ alembic -c $(ALEMBIC_CONFIG ) downgrade -1
2826
+
2827
+ .PHONY : db-current
2828
+ db-current : # # Show current database revision
2829
+ @echo " 🗄️ Current database revision:"
2830
+ @alembic -c $(ALEMBIC_CONFIG ) current
2831
+
2832
+ .PHONY : db-history
2833
+ db-history : # # Show migration history
2834
+ @echo " 🗄️ Migration history:"
2835
+ @alembic -c $(ALEMBIC_CONFIG ) history
2836
+
2837
+ .PHONY : db-heads
2838
+ db-heads : # # Show available heads
2839
+ @echo " �️ Available heads:"
2840
+ @alembic -c $(ALEMBIC_CONFIG ) heads
2841
+
2842
+ .PHONY : db-show
2843
+ db-show : # # Show a specific revision
2844
+ @read -p " Enter revision ID: " rev; \
2845
+ alembic -c $(ALEMBIC_CONFIG ) show $$ rev
2846
+
2847
+ .PHONY : db-stamp
2848
+ db-stamp : # # Stamp database with a specific revision
2849
+ @read -p " Enter revision to stamp: " rev; \
2850
+ alembic -c $(ALEMBIC_CONFIG ) stamp $$ rev
2851
+
2852
+ .PHONY : db-reset
2853
+ db-reset : # # Reset database (CAUTION: drops all data)
2854
+ @echo " ⚠️ WARNING: This will drop all data!"
2855
+ @read -p " Are you sure? (y/N): " confirm; \
2856
+ if [ " $$ confirm" = " y" ]; then \
2857
+ alembic -c $(ALEMBIC_CONFIG ) downgrade base && \
2858
+ alembic -c $(ALEMBIC_CONFIG ) upgrade head; \
2859
+ echo " ✅ Database reset complete" ; \
2860
+ else \
2861
+ echo " ❌ Database reset cancelled" ; \
2862
+ fi
2813
2863
2814
- db-history :
2815
- $(ALEMBIC ) -c mcpgateway/alembic.ini history --verbose
2864
+ .PHONY : db-status
2865
+ db-status : # # Show detailed database status
2866
+ @echo " �️ Database Status:"
2867
+ @echo " Current revision:"
2868
+ @alembic -c $(ALEMBIC_CONFIG ) current
2869
+ @echo " "
2870
+ @echo " Pending migrations:"
2871
+ @alembic -c $(ALEMBIC_CONFIG ) history -r current:head
2872
+
2873
+ .PHONY : db-check
2874
+ db-check : # # Check if migrations are up to date
2875
+ @echo " 🗄️ Checking migration status..."
2876
+ @if alembic -c $(ALEMBIC_CONFIG ) current | grep -q " (head)" ; then \
2877
+ echo " ✅ Database is up to date" ; \
2878
+ else \
2879
+ echo " ⚠️ Database needs migration" ; \
2880
+ echo " Run 'make db-upgrade' to apply pending migrations" ; \
2881
+ exit 1; \
2882
+ fi
2816
2883
2817
- db-revision-id :
2818
- @$(ALEMBIC ) -c mcpgateway/alembic.ini current --verbose | awk ' /Current revision/ {print $$3}'
2884
+ .PHONY : db-fix-head
2885
+ db-fix-head : # # Fix multiple heads issue
2886
+ @echo " �️ Fixing multiple heads..."
2887
+ alembic -c $(ALEMBIC_CONFIG ) merge -m " merge heads"
2819
2888
2820
2889
2821
2890
# =============================================================================
0 commit comments