@atlashub/smartstack-cli 1.14.3 → 1.17.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 +74897 -1477
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
- package/templates/agents/efcore/migration.md +37 -25
- package/templates/agents/efcore/rebase-snapshot.md +32 -12
- package/templates/agents/efcore/squash.md +14 -4
- package/templates/agents/mcp-healthcheck.md +161 -0
- package/templates/commands/efcore/_shared.md +117 -0
- package/templates/commands/efcore/db-deploy.md +32 -4
- package/templates/commands/efcore/db-reset.md +38 -2
- package/templates/commands/efcore/db-status.md +24 -6
- package/templates/commands/efcore/migration.md +57 -9
- package/templates/commands/efcore/rebase-snapshot.md +56 -3
- package/templates/commands/efcore/squash.md +72 -17
- package/templates/hooks/mcp-check.md +64 -0
- package/templates/skills/application/SKILL.md +50 -4
- package/templates/skills/application/steps/step-00-init.md +153 -0
- package/templates/skills/application/steps/step-01-navigation.md +144 -0
- package/templates/skills/application/steps/step-02-permissions.md +159 -0
- package/templates/skills/application/steps/step-03-roles.md +158 -0
- package/templates/skills/application/steps/step-04-backend.md +202 -0
- package/templates/skills/application/steps/step-05-frontend.md +218 -0
- package/templates/skills/application/steps/step-06-migration.md +190 -0
- package/templates/skills/gitflow/steps/step-commit.md +25 -20
- package/templates/skills/gitflow/steps/step-start.md +9 -0
- package/templates/skills/mcp/SKILL.md +246 -0
- package/templates/skills/review-code/SKILL.md +77 -0
- package/templates/skills/review-code/references/smartstack-conventions.md +302 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlashub/smartstack-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0",
|
|
4
4
|
"description": "SmartStack Claude Code automation toolkit - GitFlow, APEX, EF Core migrations, prompts and more",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SmartStack",
|
|
@@ -70,19 +70,23 @@
|
|
|
70
70
|
"health": "node dist/index.js doctor --json"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
+
"bcryptjs": "^2.4.3",
|
|
73
74
|
"chalk": "^5.3.0",
|
|
74
75
|
"cli-table3": "^0.6.3",
|
|
75
76
|
"commander": "^12.0.0",
|
|
76
77
|
"fs-extra": "^11.2.0",
|
|
77
78
|
"inquirer": "^9.2.12",
|
|
78
79
|
"jsonwebtoken": "^9.0.3",
|
|
80
|
+
"mssql": "^11.0.1",
|
|
79
81
|
"ora": "^8.0.1",
|
|
80
82
|
"zod": "^3.22.4"
|
|
81
83
|
},
|
|
82
84
|
"devDependencies": {
|
|
85
|
+
"@types/bcryptjs": "^2.4.6",
|
|
83
86
|
"@types/fs-extra": "^11.0.4",
|
|
84
87
|
"@types/inquirer": "^9.0.7",
|
|
85
88
|
"@types/jsonwebtoken": "^9.0.10",
|
|
89
|
+
"@types/mssql": "^9.1.5",
|
|
86
90
|
"@types/node": "^20.10.6",
|
|
87
91
|
"@typescript-eslint/eslint-plugin": "^6.18.0",
|
|
88
92
|
"@typescript-eslint/parser": "^6.18.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: efcore-migration
|
|
3
|
-
description: EF Core migration manager -
|
|
3
|
+
description: EF Core migration manager - orchestrates MCP for naming (1 per feature)
|
|
4
4
|
color: magenta
|
|
5
5
|
model: sonnet
|
|
6
6
|
tools: Bash, Glob, Read, Edit
|
|
@@ -8,10 +8,24 @@ tools: Bash, Glob, Read, Edit
|
|
|
8
8
|
|
|
9
9
|
# EF Core Migration Agent
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Orchestrates migration creation with the "1 migration per feature" rule.
|
|
12
|
+
|
|
13
|
+
> **IMPORTANT:** Cet agent **ORCHESTRE** uniquement. Le nommage est **DÉLÉGUÉ AU MCP**.
|
|
12
14
|
|
|
13
15
|
> **CLAUDE INSTRUCTION:** The `AskUserQuestion({...})` blocks are instructions to use the `AskUserQuestion` tool **interactively**. You MUST execute the tool with these parameters to get the user's response BEFORE continuing.
|
|
14
16
|
|
|
17
|
+
## Principe : Délégation au MCP
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
|
21
|
+
│ Agent (CLI) │─────▶│ MCP │─────▶│ dotnet ef │
|
|
22
|
+
│ Orchestre │ │ Génère le nom │ │ Crée migration │
|
|
23
|
+
└─────────────────┘ └─────────────────┘ └─────────────────┘
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**INTERDIT :** Calculer le nom de migration dans cet agent.
|
|
27
|
+
**OBLIGATOIRE :** Appeler `mcp__smartstack__suggest_migration` pour obtenir le nom.
|
|
28
|
+
|
|
15
29
|
## Dual DbContext Architecture
|
|
16
30
|
|
|
17
31
|
SmartStack uses two separate DbContexts with separate migration histories:
|
|
@@ -29,53 +43,51 @@ SmartStack uses two separate DbContexts with separate migration histories:
|
|
|
29
43
|
## Workflow
|
|
30
44
|
|
|
31
45
|
1. **Detect** DbContext type (Core vs Extensions)
|
|
32
|
-
2. **
|
|
33
|
-
3. **
|
|
46
|
+
2. **Ask** user for migration description
|
|
47
|
+
3. **Call MCP** `mcp__smartstack__suggest_migration` with description and context
|
|
34
48
|
4. **Search** for existing migration for this branch
|
|
35
49
|
5. **If exists**: propose to recreate (delete + create)
|
|
36
|
-
6. **
|
|
37
|
-
7. **
|
|
38
|
-
|
|
50
|
+
6. **Create** migration with `dotnet ef migrations add <MCP_NAME> --context {DbContext}`
|
|
51
|
+
7. **Validate** generated content
|
|
52
|
+
|
|
53
|
+
## Naming : Délégation MCP
|
|
39
54
|
|
|
40
|
-
|
|
55
|
+
**TOUJOURS appeler le MCP pour le nommage :**
|
|
41
56
|
|
|
42
57
|
```
|
|
43
|
-
{
|
|
58
|
+
mcp__smartstack__suggest_migration({
|
|
59
|
+
description: "<user_description>",
|
|
60
|
+
context: "core" | "extensions"
|
|
61
|
+
})
|
|
44
62
|
```
|
|
45
63
|
|
|
46
|
-
|
|
47
|
-
- `core_v1.8.0_001_CreateAuthUsers`
|
|
48
|
-
- `core_v1.8.0_002_AddEntraSync`
|
|
64
|
+
Le MCP retourne le nom complet conforme : `{context}_v{version}_{sequence}_{Description}`
|
|
49
65
|
|
|
50
|
-
**
|
|
66
|
+
**Exemples de noms générés par le MCP :**
|
|
67
|
+
- `core_v1.8.0_001_CreateAuthUsers`
|
|
51
68
|
- `ext_v1.0.0_001_CreateOrders`
|
|
52
|
-
- `ext_v1.0.0_002_AddOrderItems`
|
|
53
69
|
|
|
54
70
|
## Commands
|
|
55
71
|
|
|
56
72
|
```bash
|
|
57
|
-
# Branch
|
|
58
|
-
git branch --show-current
|
|
59
|
-
|
|
60
|
-
# Version
|
|
61
|
-
grep -oP '"version":\s*"\K[^"]+' package.json
|
|
62
|
-
|
|
63
73
|
# Existing migrations for Core
|
|
64
74
|
find Migrations -name "core_*.cs" | grep -v Designer | grep -v Snapshot
|
|
65
75
|
|
|
66
76
|
# Existing migrations for Extensions
|
|
67
77
|
find Persistence/Migrations -name "ext_*.cs" | grep -v Designer | grep -v Snapshot
|
|
68
78
|
|
|
69
|
-
# Create Core migration
|
|
70
|
-
dotnet ef migrations add $
|
|
79
|
+
# Create Core migration (use MCP_NAME from suggest_migration)
|
|
80
|
+
dotnet ef migrations add $MCP_NAME --context CoreDbContext -o Persistence/Migrations
|
|
71
81
|
|
|
72
|
-
# Create Extensions migration
|
|
73
|
-
dotnet ef migrations add $
|
|
82
|
+
# Create Extensions migration (use MCP_NAME from suggest_migration)
|
|
83
|
+
dotnet ef migrations add $MCP_NAME --context ExtensionsDbContext -o Persistence/Migrations
|
|
74
84
|
|
|
75
|
-
# Delete
|
|
85
|
+
# Delete existing migration
|
|
76
86
|
rm Persistence/Migrations/*${OLD_NAME}*.cs
|
|
77
87
|
```
|
|
78
88
|
|
|
89
|
+
> **Note:** `$MCP_NAME` est obtenu via l'appel MCP, jamais calculé localement.
|
|
90
|
+
|
|
79
91
|
## Context Detection
|
|
80
92
|
|
|
81
93
|
If unable to auto-detect:
|
|
@@ -21,35 +21,55 @@ Rebases ModelSnapshot on develop to resolve conflicts.
|
|
|
21
21
|
## Key Commands
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
|
+
# Détection projet et DbContext
|
|
25
|
+
detect_efcore_project # → $DBCONTEXT, $DBCONTEXT_TYPE, $SCHEMA
|
|
26
|
+
determine_base_branch # → $BASE_BRANCH, $BRANCH_TYPE
|
|
27
|
+
|
|
24
28
|
# Backup
|
|
25
29
|
BACKUP_DIR=".claude/gitflow/backup/migrations/rebase_$(date +%Y%m%d_%H%M%S)"
|
|
26
30
|
mkdir -p "$BACKUP_DIR"
|
|
27
31
|
cp Migrations/*.cs "$BACKUP_DIR/"
|
|
28
32
|
|
|
29
|
-
# Reset snapshot to develop
|
|
30
|
-
git
|
|
33
|
+
# Reset snapshot to parent branch (develop ou main selon contexte)
|
|
34
|
+
git fetch origin "$BASE_BRANCH"
|
|
35
|
+
git checkout "origin/$BASE_BRANCH" -- Migrations/*ModelSnapshot.cs
|
|
36
|
+
|
|
37
|
+
# Récupérer les migrations de la branche parente
|
|
38
|
+
BASE_MIGS=$(git ls-tree -r --name-only "origin/$BASE_BRANCH" -- Migrations/ | grep "\.cs$" | grep -v "Designer\|Snapshot")
|
|
39
|
+
for base_mig in $BASE_MIGS; do
|
|
40
|
+
base_name=$(basename "${base_mig%.cs}")
|
|
41
|
+
git checkout "origin/$BASE_BRANCH" -- "Migrations/${base_name}.cs" 2>/dev/null || true
|
|
42
|
+
git checkout "origin/$BASE_BRANCH" -- "Migrations/${base_name}.Designer.cs" 2>/dev/null || true
|
|
43
|
+
done
|
|
44
|
+
|
|
45
|
+
# Delete branch migrations only
|
|
46
|
+
rm -f Migrations/*${BRANCH_TYPE}_*.cs
|
|
47
|
+
rm -f Migrations/*${BRANCH_TYPE}_*.Designer.cs
|
|
31
48
|
|
|
32
|
-
#
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
# Regenerate with MCP naming - OBLIGATOIRE
|
|
50
|
+
mcp__smartstack__suggest_migration({ description: "...", context: DBCONTEXT_TYPE })
|
|
51
|
+
# Résultat: core_v1.7.0_001_UserAuthConsolidated
|
|
35
52
|
|
|
36
|
-
|
|
37
|
-
dotnet ef migrations add Feature_1_7_0_Consolidated
|
|
53
|
+
dotnet ef migrations add "$MIGRATION_NAME" --context "$DBCONTEXT"
|
|
38
54
|
|
|
39
55
|
# Validate
|
|
40
56
|
dotnet build
|
|
41
57
|
```
|
|
42
58
|
|
|
43
|
-
## Migration Naming
|
|
59
|
+
## Migration Naming (via MCP)
|
|
60
|
+
|
|
61
|
+
**OBLIGATOIRE : Utiliser le MCP pour le nommage**
|
|
44
62
|
|
|
45
63
|
```
|
|
46
|
-
{
|
|
64
|
+
{context}_v{version}_{sequence}_{Description}
|
|
47
65
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
66
|
+
core_v1.7.0_001_UserAuthConsolidated
|
|
67
|
+
core_v1.6.2_001_LoginFixFix
|
|
68
|
+
core_v1.7.0_001_ReleaseInitial
|
|
51
69
|
```
|
|
52
70
|
|
|
71
|
+
> **INTERDIT :** Pattern ancien `Feature_1_7_0_UserAuth_Consolidated`
|
|
72
|
+
|
|
53
73
|
## Safety Checks
|
|
54
74
|
|
|
55
75
|
- [ ] Clean working directory
|
|
@@ -40,24 +40,34 @@ main → BLOQUÉ (jamais squash)
|
|
|
40
40
|
determine_base_branch # → BASE_BRANCH, BRANCH_TYPE
|
|
41
41
|
|
|
42
42
|
# Identifier migrations propres à la branche
|
|
43
|
-
BASE_MIGS=$(git ls-tree -r --name-only "origin/$BASE_BRANCH" -- Migrations/)
|
|
43
|
+
BASE_MIGS=$(git ls-tree -r --name-only "origin/$BASE_BRANCH" -- Migrations/ | grep "\.cs$" | grep -v "Designer\|Snapshot")
|
|
44
44
|
LOCAL_MIGS=$(find Migrations -name "*.cs" | grep -v Designer | grep -v Snapshot)
|
|
45
45
|
|
|
46
46
|
# Backup
|
|
47
47
|
BACKUP_DIR=".claude/gitflow/backup/migrations/squash_$(date +%Y%m%d_%H%M%S)"
|
|
48
48
|
mkdir -p "$BACKUP_DIR" && cp Migrations/*.cs "$BACKUP_DIR/"
|
|
49
49
|
|
|
50
|
-
# CRUCIAL: Récupérer snapshot
|
|
50
|
+
# CRUCIAL: Récupérer snapshot ET migrations de la branche parente
|
|
51
51
|
git fetch origin "$BASE_BRANCH"
|
|
52
52
|
git checkout "origin/$BASE_BRANCH" -- Migrations/*ModelSnapshot.cs
|
|
53
53
|
|
|
54
|
+
# Récupérer les migrations de la branche parente (pour ne pas les perdre)
|
|
55
|
+
for base_mig in $BASE_MIGS; do
|
|
56
|
+
base_name=$(basename "${base_mig%.cs}")
|
|
57
|
+
git checkout "origin/$BASE_BRANCH" -- "Migrations/${base_name}.cs" 2>/dev/null || true
|
|
58
|
+
git checkout "origin/$BASE_BRANCH" -- "Migrations/${base_name}.Designer.cs" 2>/dev/null || true
|
|
59
|
+
done
|
|
60
|
+
|
|
54
61
|
# Supprimer migrations de la branche uniquement
|
|
55
62
|
for mig in $BRANCH_ONLY_MIGRATIONS; do
|
|
56
63
|
rm -f "Migrations/${mig}"*
|
|
57
64
|
done
|
|
58
65
|
|
|
59
|
-
# Créer migration consolidée
|
|
60
|
-
|
|
66
|
+
# Créer migration consolidée - UTILISER MCP OBLIGATOIRE
|
|
67
|
+
mcp__smartstack__suggest_migration({ description: "...", context: "core" })
|
|
68
|
+
# Résultat: core_v1.0.0_001_Description
|
|
69
|
+
|
|
70
|
+
dotnet ef migrations add "$MIGRATION_NAME_FROM_MCP"
|
|
61
71
|
|
|
62
72
|
# Valider
|
|
63
73
|
dotnet build && dotnet ef migrations script --idempotent > /dev/null
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mcp-healthcheck
|
|
3
|
+
description: Verifies MCP server availability, version and configuration before operations
|
|
4
|
+
color: cyan
|
|
5
|
+
model: haiku
|
|
6
|
+
tools: Bash, Read, Write, Glob
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# MCP Health Check Agent
|
|
10
|
+
|
|
11
|
+
Validates that SmartStack MCP is properly configured and up-to-date before any operation.
|
|
12
|
+
|
|
13
|
+
## Status File
|
|
14
|
+
|
|
15
|
+
Location: `.claude/mcp-status.json`
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"lastCheck": "2024-01-15T10:30:00Z",
|
|
20
|
+
"mcpVersion": "1.5.0",
|
|
21
|
+
"mcpPath": "D:\\01 - projets\\SmartStack.mcp",
|
|
22
|
+
"status": "ok",
|
|
23
|
+
"tools": ["validate_conventions", "scaffold_extension", "check_migrations", "..."]
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Workflow
|
|
28
|
+
|
|
29
|
+
### 1. Check Status File Age
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Read last check timestamp
|
|
33
|
+
cat .claude/mcp-status.json 2>/dev/null | grep lastCheck
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Decision:**
|
|
37
|
+
- File missing → Full check required
|
|
38
|
+
- Last check > 7 days → Full check required
|
|
39
|
+
- Last check ≤ 7 days → Quick validation only
|
|
40
|
+
|
|
41
|
+
### 2. Quick Validation (≤ 7 days)
|
|
42
|
+
|
|
43
|
+
Test MCP connectivity with a lightweight call:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
Call: mcp__smartstack__validate_conventions with checks=["tables"]
|
|
47
|
+
Expected: Response without connection error
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If fails → Run full check
|
|
51
|
+
|
|
52
|
+
### 3. Full Check (> 7 days or missing)
|
|
53
|
+
|
|
54
|
+
#### 3.1 Verify MCP Server Configuration
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# Check Claude Code MCP config
|
|
58
|
+
cat ~/.claude/settings.json | grep -A 20 "smartstack"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### 3.2 Test MCP Tools Availability
|
|
62
|
+
|
|
63
|
+
Call each critical tool to verify availability:
|
|
64
|
+
|
|
65
|
+
| Tool | Test Call |
|
|
66
|
+
|------|-----------|
|
|
67
|
+
| `validate_conventions` | `checks=["tables"]` |
|
|
68
|
+
| `suggest_migration` | `description="test"` |
|
|
69
|
+
| `check_migrations` | (no params) |
|
|
70
|
+
|
|
71
|
+
#### 3.3 Check MCP Version
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
# Read MCP package.json
|
|
75
|
+
cat "D:\\01 - projets\\SmartStack.mcp\\package.json" | grep version
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### 3.4 Compare with Latest Release
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Check npm registry for latest version
|
|
82
|
+
npm view @anthropic/smartstack-mcp version 2>/dev/null || echo "Not published"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 4. Update Status File
|
|
86
|
+
|
|
87
|
+
```javascript
|
|
88
|
+
Write(".claude/mcp-status.json", {
|
|
89
|
+
lastCheck: new Date().toISOString(),
|
|
90
|
+
mcpVersion: "<detected_version>",
|
|
91
|
+
mcpPath: "<configured_path>",
|
|
92
|
+
status: "ok" | "error",
|
|
93
|
+
tools: ["<available_tools>"],
|
|
94
|
+
errors: ["<any_errors>"] // if status = error
|
|
95
|
+
})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Output Format
|
|
99
|
+
|
|
100
|
+
### Success
|
|
101
|
+
```
|
|
102
|
+
MCP HEALTH CHECK
|
|
103
|
+
Status: ✓ OK
|
|
104
|
+
Version: 1.5.0 (latest)
|
|
105
|
+
Last check: 2024-01-15
|
|
106
|
+
Tools available: 12/12
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Warning (outdated)
|
|
110
|
+
```
|
|
111
|
+
MCP HEALTH CHECK
|
|
112
|
+
Status: ⚠️ UPDATE AVAILABLE
|
|
113
|
+
Current: 1.4.0
|
|
114
|
+
Latest: 1.5.0
|
|
115
|
+
Action: Run `cd SmartStack.mcp && git pull`
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Error
|
|
119
|
+
```
|
|
120
|
+
MCP HEALTH CHECK
|
|
121
|
+
Status: ❌ ERROR
|
|
122
|
+
Issue: MCP server not responding
|
|
123
|
+
Action: Verify MCP configuration in Claude Code settings
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Integration
|
|
127
|
+
|
|
128
|
+
This agent should be called:
|
|
129
|
+
1. **Before any MCP-dependent operation** (scaffold, validate, migrate)
|
|
130
|
+
2. **On CLI installation/update**
|
|
131
|
+
3. **Manually via `/mcp:healthcheck`**
|
|
132
|
+
|
|
133
|
+
## Caching Logic
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
┌─────────────────────┐
|
|
137
|
+
│ Operation Start │
|
|
138
|
+
└──────────┬──────────┘
|
|
139
|
+
▼
|
|
140
|
+
┌─────────────────────┐
|
|
141
|
+
│ Read mcp-status.json│
|
|
142
|
+
└──────────┬──────────┘
|
|
143
|
+
▼
|
|
144
|
+
┌──────────────┐
|
|
145
|
+
│ File exists? │
|
|
146
|
+
└──────┬───────┘
|
|
147
|
+
│
|
|
148
|
+
No ───┼─── Yes
|
|
149
|
+
│ │
|
|
150
|
+
▼ ▼
|
|
151
|
+
┌──────────────────┐
|
|
152
|
+
│ > 7 days old? │
|
|
153
|
+
└──────┬───────────┘
|
|
154
|
+
│
|
|
155
|
+
Yes ──┼─── No
|
|
156
|
+
│ │
|
|
157
|
+
▼ ▼
|
|
158
|
+
┌──────────────┐ ┌──────────────┐
|
|
159
|
+
│ Full Check │ │ Quick Check │
|
|
160
|
+
└──────────────┘ └──────────────┘
|
|
161
|
+
```
|
|
@@ -16,6 +16,94 @@ detect_efcore_project() {
|
|
|
16
16
|
STARTUP_PROJECT=$(find . -name "*.Api.csproj" -o -name "*Web.csproj" | head -1)
|
|
17
17
|
INFRA_PROJECT=$(find . -name "*Infrastructure.csproj" | head -1)
|
|
18
18
|
[ -z "$INFRA_PROJECT" ] && INFRA_PROJECT="$CSPROJ"
|
|
19
|
+
|
|
20
|
+
# Appeler la détection du DbContext
|
|
21
|
+
detect_dbcontext
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Détection DbContext (Core vs Extensions)
|
|
28
|
+
|
|
29
|
+
SmartStack utilise **deux DbContext séparés** avec des historiques de migration distincts :
|
|
30
|
+
|
|
31
|
+
| Context | DbContext | Schema | History Table |
|
|
32
|
+
|---------|-----------|--------|---------------|
|
|
33
|
+
| `core` | `CoreDbContext` | `core` | `core.__EFMigrationsHistory` |
|
|
34
|
+
| `extensions` | `ExtensionsDbContext` | `extensions` | `extensions.__EFMigrationsHistory` |
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
detect_dbcontext() {
|
|
38
|
+
# 1. Vérifier si SmartStack.Domain existe → CoreDbContext
|
|
39
|
+
if find . -type d -name "SmartStack.Domain" | grep -q .; then
|
|
40
|
+
DBCONTEXT="CoreDbContext"
|
|
41
|
+
DBCONTEXT_TYPE="core"
|
|
42
|
+
SCHEMA="core"
|
|
43
|
+
echo "DbContext détecté: CoreDbContext (SmartStack.Domain trouvé)"
|
|
44
|
+
return
|
|
45
|
+
fi
|
|
46
|
+
|
|
47
|
+
# 2. Vérifier si projet client avec NuGet SmartStack → ExtensionsDbContext
|
|
48
|
+
if find . -name "*.csproj" -exec grep -l "SmartStack\." {} \; | grep -qv "SmartStack\."; then
|
|
49
|
+
DBCONTEXT="ExtensionsDbContext"
|
|
50
|
+
DBCONTEXT_TYPE="extensions"
|
|
51
|
+
SCHEMA="extensions"
|
|
52
|
+
echo "DbContext détecté: ExtensionsDbContext (Client avec NuGet SmartStack)"
|
|
53
|
+
return
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
# 3. Vérifier les DbContext présents dans le code
|
|
57
|
+
CORE_CTX=$(find . -name "*.cs" -exec grep -l "CoreDbContext" {} \; 2>/dev/null | head -1)
|
|
58
|
+
EXT_CTX=$(find . -name "*.cs" -exec grep -l "ExtensionsDbContext" {} \; 2>/dev/null | head -1)
|
|
59
|
+
|
|
60
|
+
if [ -n "$CORE_CTX" ] && [ -z "$EXT_CTX" ]; then
|
|
61
|
+
DBCONTEXT="CoreDbContext"
|
|
62
|
+
DBCONTEXT_TYPE="core"
|
|
63
|
+
SCHEMA="core"
|
|
64
|
+
elif [ -z "$CORE_CTX" ] && [ -n "$EXT_CTX" ]; then
|
|
65
|
+
DBCONTEXT="ExtensionsDbContext"
|
|
66
|
+
DBCONTEXT_TYPE="extensions"
|
|
67
|
+
SCHEMA="extensions"
|
|
68
|
+
else
|
|
69
|
+
# 4. Les deux existent ou aucun trouvé → demander à l'utilisateur
|
|
70
|
+
DBCONTEXT=""
|
|
71
|
+
DBCONTEXT_TYPE=""
|
|
72
|
+
SCHEMA=""
|
|
73
|
+
echo "⚠️ DbContext non détecté automatiquement"
|
|
74
|
+
echo "→ Utiliser AskUserQuestion pour demander à l'utilisateur"
|
|
75
|
+
fi
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Variables exportées :**
|
|
80
|
+
|
|
81
|
+
| Variable | Valeurs possibles | Description |
|
|
82
|
+
|----------|-------------------|-------------|
|
|
83
|
+
| `$DBCONTEXT` | `CoreDbContext` / `ExtensionsDbContext` | Nom du DbContext |
|
|
84
|
+
| `$DBCONTEXT_TYPE` | `core` / `extensions` | Type pour le MCP |
|
|
85
|
+
| `$SCHEMA` | `core` / `extensions` | Schéma de base de données |
|
|
86
|
+
|
|
87
|
+
**Si détection échoue, demander à l'utilisateur :**
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
AskUserQuestion({
|
|
91
|
+
questions: [{
|
|
92
|
+
question: "Quel DbContext utiliser pour cette migration ?",
|
|
93
|
+
header: "DbContext",
|
|
94
|
+
options: [
|
|
95
|
+
{ label: "CoreDbContext", description: "Entités SmartStack (User, Role, Navigation...)" },
|
|
96
|
+
{ label: "ExtensionsDbContext", description: "Entités client spécifiques" }
|
|
97
|
+
],
|
|
98
|
+
multiSelect: false
|
|
99
|
+
}]
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// Puis définir les variables selon la réponse
|
|
103
|
+
if (answer === "CoreDbContext") {
|
|
104
|
+
DBCONTEXT="CoreDbContext"; DBCONTEXT_TYPE="core"; SCHEMA="core";
|
|
105
|
+
} else {
|
|
106
|
+
DBCONTEXT="ExtensionsDbContext"; DBCONTEXT_TYPE="extensions"; SCHEMA="extensions";
|
|
19
107
|
}
|
|
20
108
|
```
|
|
21
109
|
|
|
@@ -155,6 +243,8 @@ determine_base_branch() {
|
|
|
155
243
|
|
|
156
244
|
## Convention Nommage Migration
|
|
157
245
|
|
|
246
|
+
**OBLIGATOIRE : Utiliser le MCP pour le nommage**
|
|
247
|
+
|
|
158
248
|
Pattern: `{context}_v{version}_{sequence}_{Description}`
|
|
159
249
|
|
|
160
250
|
| Contexte | Version | Séquence | Description | Exemple |
|
|
@@ -162,6 +252,33 @@ Pattern: `{context}_v{version}_{sequence}_{Description}`
|
|
|
162
252
|
| core | 1.2.0 | 001 | AddUserRoles | `core_v1.2.0_001_AddUserRoles` |
|
|
163
253
|
| extensions | 1.3.0 | 001 | AddCustomFields | `extensions_v1.3.0_001_AddCustomFields` |
|
|
164
254
|
|
|
255
|
+
**Appel MCP OBLIGATOIRE :**
|
|
256
|
+
|
|
257
|
+
```javascript
|
|
258
|
+
// TOUJOURS appeler le MCP pour obtenir le nom conforme
|
|
259
|
+
mcp__smartstack__suggest_migration({
|
|
260
|
+
description: "Add User Roles", // Description courte
|
|
261
|
+
context: DBCONTEXT_TYPE // "core" ou "extensions" (de detect_dbcontext)
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
// Résultat: core_v1.2.0_001_AddUserRoles
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Création migration avec le nom MCP :**
|
|
268
|
+
|
|
269
|
+
```bash
|
|
270
|
+
# $MIGRATION_NAME = résultat du MCP
|
|
271
|
+
# $DBCONTEXT = CoreDbContext ou ExtensionsDbContext (de detect_dbcontext)
|
|
272
|
+
|
|
273
|
+
dotnet ef migrations add "$MIGRATION_NAME" \
|
|
274
|
+
--context "$DBCONTEXT" \
|
|
275
|
+
--project "$INFRA_PROJECT" \
|
|
276
|
+
--startup-project "$STARTUP_PROJECT" \
|
|
277
|
+
-o Persistence/Migrations
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
> **INTERDIT :** Calculer le nom de migration manuellement. Toujours déléguer au MCP.
|
|
281
|
+
|
|
165
282
|
---
|
|
166
283
|
|
|
167
284
|
## Règle d'Or: 1 Migration par Feature
|
|
@@ -21,10 +21,28 @@ Afficher: fichiers disponibles, environnement sélectionné, connexion cible.
|
|
|
21
21
|
|
|
22
22
|
---
|
|
23
23
|
|
|
24
|
-
## STEP 1: Détecter Projet
|
|
24
|
+
## STEP 1: Détecter Projet et DbContext
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
|
-
detect_efcore_project
|
|
27
|
+
detect_efcore_project # Appelle detect_dbcontext() automatiquement
|
|
28
|
+
echo "DbContext: $DBCONTEXT ($DBCONTEXT_TYPE)"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Si DbContext non détecté automatiquement :**
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
AskUserQuestion({
|
|
35
|
+
questions: [{
|
|
36
|
+
question: "Quel DbContext déployer ?",
|
|
37
|
+
header: "DbContext",
|
|
38
|
+
options: [
|
|
39
|
+
{ label: "CoreDbContext", description: "Migrations du schéma core" },
|
|
40
|
+
{ label: "ExtensionsDbContext", description: "Migrations du schéma extensions" },
|
|
41
|
+
{ label: "Les deux", description: "Déployer core puis extensions" }
|
|
42
|
+
],
|
|
43
|
+
multiSelect: false
|
|
44
|
+
}]
|
|
45
|
+
})
|
|
28
46
|
```
|
|
29
47
|
|
|
30
48
|
---
|
|
@@ -32,7 +50,11 @@ detect_efcore_project
|
|
|
32
50
|
## STEP 2: Vérifier Migrations Pending
|
|
33
51
|
|
|
34
52
|
```bash
|
|
35
|
-
PENDING_COUNT=$(dotnet ef migrations list
|
|
53
|
+
PENDING_COUNT=$(dotnet ef migrations list \
|
|
54
|
+
--context "$DBCONTEXT" \
|
|
55
|
+
--project "$INFRA_PROJECT" \
|
|
56
|
+
--startup-project "$STARTUP_PROJECT" \
|
|
57
|
+
--json | grep -c '"applied": false')
|
|
36
58
|
```
|
|
37
59
|
|
|
38
60
|
---
|
|
@@ -40,9 +62,15 @@ PENDING_COUNT=$(dotnet ef migrations list --json | grep -c '"applied": false')
|
|
|
40
62
|
## STEP 3: Appliquer
|
|
41
63
|
|
|
42
64
|
```bash
|
|
43
|
-
dotnet ef database update
|
|
65
|
+
dotnet ef database update \
|
|
66
|
+
--context "$DBCONTEXT" \
|
|
67
|
+
--project "$INFRA_PROJECT" \
|
|
68
|
+
--startup-project "$STARTUP_PROJECT" \
|
|
69
|
+
--verbose
|
|
44
70
|
```
|
|
45
71
|
|
|
72
|
+
> **Note :** Si "Les deux" sélectionné, exécuter pour CoreDbContext puis ExtensionsDbContext.
|
|
73
|
+
|
|
46
74
|
---
|
|
47
75
|
|
|
48
76
|
## Résumé
|
|
@@ -81,18 +81,54 @@ backup_database # Fonction de _shared.md
|
|
|
81
81
|
|
|
82
82
|
---
|
|
83
83
|
|
|
84
|
+
## STEP 2.5: Détection DbContext
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
detect_efcore_project # Appelle detect_dbcontext() automatiquement
|
|
88
|
+
echo "DbContext: $DBCONTEXT"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Si DbContext non détecté ou plusieurs contextes :**
|
|
92
|
+
|
|
93
|
+
```javascript
|
|
94
|
+
AskUserQuestion({
|
|
95
|
+
questions: [{
|
|
96
|
+
question: "Quel DbContext reset ? (ou 'both' pour les deux)",
|
|
97
|
+
header: "DbContext",
|
|
98
|
+
options: [
|
|
99
|
+
{ label: "CoreDbContext", description: "Reset schéma core uniquement" },
|
|
100
|
+
{ label: "ExtensionsDbContext", description: "Reset schéma extensions uniquement" },
|
|
101
|
+
{ label: "Les deux", description: "Reset complet (core + extensions)" }
|
|
102
|
+
],
|
|
103
|
+
multiSelect: false
|
|
104
|
+
}]
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
84
110
|
## STEP 3: Drop Database
|
|
85
111
|
|
|
86
112
|
```bash
|
|
87
|
-
dotnet ef database drop
|
|
113
|
+
dotnet ef database drop \
|
|
114
|
+
--context "$DBCONTEXT" \
|
|
115
|
+
--project "$INFRA_PROJECT" \
|
|
116
|
+
--startup-project "$STARTUP_PROJECT" \
|
|
117
|
+
--force
|
|
88
118
|
```
|
|
89
119
|
|
|
120
|
+
> **Note :** Si "Les deux" sélectionné, exécuter pour CoreDbContext puis ExtensionsDbContext.
|
|
121
|
+
|
|
90
122
|
---
|
|
91
123
|
|
|
92
124
|
## STEP 4: Recreate + Apply
|
|
93
125
|
|
|
94
126
|
```bash
|
|
95
|
-
dotnet ef database update
|
|
127
|
+
dotnet ef database update \
|
|
128
|
+
--context "$DBCONTEXT" \
|
|
129
|
+
--project "$INFRA_PROJECT" \
|
|
130
|
+
--startup-project "$STARTUP_PROJECT" \
|
|
131
|
+
--verbose
|
|
96
132
|
```
|
|
97
133
|
|
|
98
134
|
---
|