@atlashub/smartstack-cli 4.36.0 → 4.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +26 -68
- package/dist/index.js.map +1 -1
- package/dist/mcp-entry.mjs +25 -1
- package/dist/mcp-entry.mjs.map +1 -1
- package/package.json +1 -1
- package/templates/agents/efcore/migration.md +43 -0
- package/templates/agents/efcore/rebase-snapshot.md +36 -0
- package/templates/agents/efcore/squash.md +36 -0
package/package.json
CHANGED
|
@@ -114,6 +114,49 @@ rm Persistence/Migrations/*${OLD_NAME}*.cs
|
|
|
114
114
|
|
|
115
115
|
> **Note:** `$MCP_NAME` is obtained via MCP call, never computed locally.
|
|
116
116
|
|
|
117
|
+
## SQL Objects Post-Injection (MANDATORY after every migration creation)
|
|
118
|
+
|
|
119
|
+
**This step is NON-OPTIONAL.** After EVERY `dotnet ef migrations add`, you MUST check for SQL objects and inject them into the generated migration. Skipping this step causes runtime 500 errors on ALL endpoints (TVFs like `fn_GetUserGroupHierarchy` won't exist in the database).
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Detect the generated migration file (the main .cs, not .Designer.cs)
|
|
123
|
+
MIGRATION_FILE=$(find "$MIGRATIONS_DIR" -name "*${MCP_NAME}.cs" ! -name "*.Designer.cs" | head -1)
|
|
124
|
+
SQL_OBJECTS_DIR="$INFRA_PROJECT_DIR/Persistence/SqlObjects"
|
|
125
|
+
SQL_FILES=$(find "$SQL_OBJECTS_DIR" -name "*.sql" 2>/dev/null | wc -l)
|
|
126
|
+
|
|
127
|
+
if [ "$SQL_FILES" -gt 0 ]; then
|
|
128
|
+
echo "Found $SQL_FILES SQL object(s) — injecting SqlObjectHelper.ApplyAll()..."
|
|
129
|
+
|
|
130
|
+
# Add using directive if not present
|
|
131
|
+
if ! grep -q "using SmartStack.Infrastructure.Persistence.SqlObjects;" "$MIGRATION_FILE"; then
|
|
132
|
+
sed -i '1s/^/using SmartStack.Infrastructure.Persistence.SqlObjects;\n/' "$MIGRATION_FILE"
|
|
133
|
+
fi
|
|
134
|
+
|
|
135
|
+
# Add SqlObjectHelper.ApplyAll at the end of Up() method
|
|
136
|
+
# Use Edit tool to insert before the closing brace of Up()
|
|
137
|
+
# Target: the last " }" before "protected override void Down"
|
|
138
|
+
sed -i '/protected override void Down/i\
|
|
139
|
+
\ // Apply SQL objects (TVF, Views, SP) from embedded resources\
|
|
140
|
+
\ SqlObjectHelper.ApplyAll(migrationBuilder);' "$MIGRATION_FILE"
|
|
141
|
+
|
|
142
|
+
# VERIFY injection succeeded — FAIL if not
|
|
143
|
+
if ! grep -q "SqlObjectHelper.ApplyAll" "$MIGRATION_FILE"; then
|
|
144
|
+
echo "ERROR: Auto-injection failed. Use Edit tool to manually add:"
|
|
145
|
+
echo " 1. Add 'using SmartStack.Infrastructure.Persistence.SqlObjects;' at top"
|
|
146
|
+
echo " 2. Add 'SqlObjectHelper.ApplyAll(migrationBuilder);' at end of Up() method"
|
|
147
|
+
echo " File: $MIGRATION_FILE"
|
|
148
|
+
# DO NOT CONTINUE — fix this before proceeding
|
|
149
|
+
else
|
|
150
|
+
echo " SqlObjectHelper.ApplyAll(migrationBuilder) injected successfully"
|
|
151
|
+
find "$SQL_OBJECTS_DIR" -name "*.sql" -exec basename {} \; | while read f; do echo " - $f"; done
|
|
152
|
+
fi
|
|
153
|
+
else
|
|
154
|
+
echo "No SQL objects found in SqlObjects/ — skipping injection"
|
|
155
|
+
fi
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
> **CRITICAL:** If the bash `sed` injection fails (indentation mismatch), use the **Edit tool** to manually insert the lines. NEVER skip this step — it causes cascading 500 errors at runtime.
|
|
159
|
+
|
|
117
160
|
## Context Detection
|
|
118
161
|
|
|
119
162
|
If unable to auto-detect:
|
|
@@ -70,6 +70,42 @@ mcp__smartstack__suggest_migration({ description: "...", context: DBCONTEXT_TYPE
|
|
|
70
70
|
|
|
71
71
|
dotnet ef migrations add "$MIGRATION_NAME" --context "$DBCONTEXT"
|
|
72
72
|
|
|
73
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
74
|
+
# MANDATORY: SQL Objects Post-Injection
|
|
75
|
+
# Without this, TVFs (fn_GetUserGroupHierarchy etc.) won't exist in DB
|
|
76
|
+
# and ALL endpoints will return 500 at runtime
|
|
77
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
78
|
+
MIGRATION_FILE=$(find Migrations -name "*${MIGRATION_NAME}.cs" ! -name "*.Designer.cs" | head -1)
|
|
79
|
+
SQL_OBJECTS_DIR="$INFRA_PROJECT_DIR/Persistence/SqlObjects"
|
|
80
|
+
SQL_FILES=$(find "$SQL_OBJECTS_DIR" -name "*.sql" 2>/dev/null | wc -l)
|
|
81
|
+
|
|
82
|
+
if [ "$SQL_FILES" -gt 0 ]; then
|
|
83
|
+
echo "Found $SQL_FILES SQL object(s) — injecting SqlObjectHelper.ApplyAll()..."
|
|
84
|
+
|
|
85
|
+
# Add using directive if not present
|
|
86
|
+
if ! grep -q "using SmartStack.Infrastructure.Persistence.SqlObjects;" "$MIGRATION_FILE"; then
|
|
87
|
+
sed -i '1s/^/using SmartStack.Infrastructure.Persistence.SqlObjects;\n/' "$MIGRATION_FILE"
|
|
88
|
+
fi
|
|
89
|
+
|
|
90
|
+
# Inject SqlObjectHelper.ApplyAll before Down() method
|
|
91
|
+
sed -i '/protected override void Down/i\
|
|
92
|
+
\ // Apply SQL objects (TVF, Views, SP) from embedded resources\
|
|
93
|
+
\ SqlObjectHelper.ApplyAll(migrationBuilder);' "$MIGRATION_FILE"
|
|
94
|
+
|
|
95
|
+
# VERIFY — FAIL if injection didn't work
|
|
96
|
+
if ! grep -q "SqlObjectHelper.ApplyAll" "$MIGRATION_FILE"; then
|
|
97
|
+
echo "ERROR: Auto-injection failed. Use Edit tool to manually add:"
|
|
98
|
+
echo " 1. 'using SmartStack.Infrastructure.Persistence.SqlObjects;' at top"
|
|
99
|
+
echo " 2. 'SqlObjectHelper.ApplyAll(migrationBuilder);' at end of Up()"
|
|
100
|
+
echo " File: $MIGRATION_FILE"
|
|
101
|
+
else
|
|
102
|
+
echo " SqlObjectHelper.ApplyAll(migrationBuilder) injected"
|
|
103
|
+
find "$SQL_OBJECTS_DIR" -name "*.sql" -exec basename {} \; | while read f; do echo " - $f"; done
|
|
104
|
+
fi
|
|
105
|
+
else
|
|
106
|
+
echo "No SQL objects found — skipping injection"
|
|
107
|
+
fi
|
|
108
|
+
|
|
73
109
|
# Validate
|
|
74
110
|
dotnet build
|
|
75
111
|
```
|
|
@@ -100,6 +100,42 @@ mcp__smartstack__suggest_migration({ description: "...", context: DBCONTEXT_TYPE
|
|
|
100
100
|
|
|
101
101
|
dotnet ef migrations add "$MIGRATION_NAME_FROM_MCP" --context "$DBCONTEXT"
|
|
102
102
|
|
|
103
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
104
|
+
# MANDATORY: SQL Objects Post-Injection
|
|
105
|
+
# Without this, TVFs (fn_GetUserGroupHierarchy etc.) won't exist in DB
|
|
106
|
+
# and ALL endpoints will return 500 at runtime
|
|
107
|
+
# ═══════════════════════════════════════════════════════════════════════════
|
|
108
|
+
MIGRATION_FILE=$(find Migrations -name "*${MIGRATION_NAME_FROM_MCP}.cs" ! -name "*.Designer.cs" | head -1)
|
|
109
|
+
SQL_OBJECTS_DIR="$INFRA_PROJECT_DIR/Persistence/SqlObjects"
|
|
110
|
+
SQL_FILES=$(find "$SQL_OBJECTS_DIR" -name "*.sql" 2>/dev/null | wc -l)
|
|
111
|
+
|
|
112
|
+
if [ "$SQL_FILES" -gt 0 ]; then
|
|
113
|
+
echo "Found $SQL_FILES SQL object(s) — injecting SqlObjectHelper.ApplyAll()..."
|
|
114
|
+
|
|
115
|
+
# Add using directive if not present
|
|
116
|
+
if ! grep -q "using SmartStack.Infrastructure.Persistence.SqlObjects;" "$MIGRATION_FILE"; then
|
|
117
|
+
sed -i '1s/^/using SmartStack.Infrastructure.Persistence.SqlObjects;\n/' "$MIGRATION_FILE"
|
|
118
|
+
fi
|
|
119
|
+
|
|
120
|
+
# Inject SqlObjectHelper.ApplyAll before Down() method
|
|
121
|
+
sed -i '/protected override void Down/i\
|
|
122
|
+
\ // Apply SQL objects (TVF, Views, SP) from embedded resources\
|
|
123
|
+
\ SqlObjectHelper.ApplyAll(migrationBuilder);' "$MIGRATION_FILE"
|
|
124
|
+
|
|
125
|
+
# VERIFY — FAIL if injection didn't work
|
|
126
|
+
if ! grep -q "SqlObjectHelper.ApplyAll" "$MIGRATION_FILE"; then
|
|
127
|
+
echo "ERROR: Auto-injection failed. Use Edit tool to manually add:"
|
|
128
|
+
echo " 1. 'using SmartStack.Infrastructure.Persistence.SqlObjects;' at top"
|
|
129
|
+
echo " 2. 'SqlObjectHelper.ApplyAll(migrationBuilder);' at end of Up()"
|
|
130
|
+
echo " File: $MIGRATION_FILE"
|
|
131
|
+
else
|
|
132
|
+
echo " SqlObjectHelper.ApplyAll(migrationBuilder) injected"
|
|
133
|
+
find "$SQL_OBJECTS_DIR" -name "*.sql" -exec basename {} \; | while read f; do echo " - $f"; done
|
|
134
|
+
fi
|
|
135
|
+
else
|
|
136
|
+
echo "No SQL objects found — skipping injection"
|
|
137
|
+
fi
|
|
138
|
+
|
|
103
139
|
# Validate
|
|
104
140
|
dotnet build && dotnet ef migrations script --idempotent > /dev/null
|
|
105
141
|
```
|