@atlashub/smartstack-cli 1.16.0 → 1.18.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.
Files changed (41) hide show
  1. package/dist/index.js +74897 -1477
  2. package/dist/index.js.map +1 -1
  3. package/package.json +5 -1
  4. package/templates/agents/efcore/db-deploy.md +5 -0
  5. package/templates/agents/efcore/db-reset.md +5 -0
  6. package/templates/agents/efcore/db-seed.md +5 -0
  7. package/templates/agents/efcore/db-status.md +5 -0
  8. package/templates/agents/efcore/migration.md +8 -0
  9. package/templates/agents/efcore/rebase-snapshot.md +41 -12
  10. package/templates/agents/efcore/squash.md +59 -19
  11. package/templates/commands/efcore/_shared.md +117 -0
  12. package/templates/commands/efcore/db-deploy.md +32 -4
  13. package/templates/commands/efcore/db-reset.md +38 -2
  14. package/templates/commands/efcore/db-status.md +24 -6
  15. package/templates/commands/efcore/migration.md +57 -9
  16. package/templates/commands/efcore/rebase-snapshot.md +56 -3
  17. package/templates/commands/efcore/squash.md +85 -18
  18. package/templates/skills/efcore/SKILL.md +162 -0
  19. package/templates/skills/efcore/steps/db/step-deploy.md +208 -0
  20. package/templates/skills/efcore/steps/db/step-reset.md +259 -0
  21. package/templates/skills/efcore/steps/db/step-seed.md +244 -0
  22. package/templates/skills/efcore/steps/db/step-status.md +198 -0
  23. package/templates/skills/efcore/steps/migration/step-00-init.md +102 -0
  24. package/templates/skills/efcore/steps/migration/step-01-check.md +138 -0
  25. package/templates/skills/efcore/steps/migration/step-02-create.md +144 -0
  26. package/templates/skills/efcore/steps/migration/step-03-validate.md +203 -0
  27. package/templates/skills/efcore/steps/rebase-snapshot/step-00-init.md +173 -0
  28. package/templates/skills/efcore/steps/rebase-snapshot/step-01-backup.md +100 -0
  29. package/templates/skills/efcore/steps/rebase-snapshot/step-02-fetch.md +115 -0
  30. package/templates/skills/efcore/steps/rebase-snapshot/step-03-create.md +108 -0
  31. package/templates/skills/efcore/steps/rebase-snapshot/step-04-validate.md +157 -0
  32. package/templates/skills/efcore/steps/shared/step-00-init.md +266 -0
  33. package/templates/skills/efcore/steps/squash/step-00-init.md +141 -0
  34. package/templates/skills/efcore/steps/squash/step-01-backup.md +120 -0
  35. package/templates/skills/efcore/steps/squash/step-02-fetch.md +168 -0
  36. package/templates/skills/efcore/steps/squash/step-03-create.md +178 -0
  37. package/templates/skills/efcore/steps/squash/step-04-validate.md +174 -0
  38. package/templates/skills/gitflow/steps/step-commit.md +25 -20
  39. package/templates/skills/gitflow/steps/step-start.md +9 -0
  40. package/templates/skills/review-code/SKILL.md +77 -0
  41. 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.16.0",
3
+ "version": "1.18.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",
@@ -4,12 +4,17 @@ description: EF Core database deploy - apply pending migrations
4
4
  color: green
5
5
  model: haiku
6
6
  tools: Bash, Glob
7
+ steps:
8
+ - steps/shared/step-00-init.md
9
+ - steps/db/step-deploy.md
7
10
  ---
8
11
 
9
12
  # EF Core Database Deploy Agent
10
13
 
11
14
  Applies pending migrations to the local database.
12
15
 
16
+ **Progressive Steps:** Load `steps/db/step-deploy.md` for detailed instructions.
17
+
13
18
  ## Workflow
14
19
 
15
20
  1. **Verify** appsettings.Local.json exists
@@ -4,12 +4,17 @@ description: EF Core database reset - drop and recreate (DESTRUCTIVE)
4
4
  color: red
5
5
  model: sonnet
6
6
  tools: Bash, Glob, Read
7
+ steps:
8
+ - steps/shared/step-00-init.md
9
+ - steps/db/step-reset.md
7
10
  ---
8
11
 
9
12
  # EF Core Database Reset Agent
10
13
 
11
14
  **WARNING: Destructive operation - deletes all data!**
12
15
 
16
+ **Progressive Steps:** Load `steps/db/step-reset.md` for detailed instructions.
17
+
13
18
  > **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
19
 
15
20
  ## Workflow
@@ -4,12 +4,17 @@ description: EF Core database seed - populate test data
4
4
  color: yellow
5
5
  model: haiku
6
6
  tools: Bash, Glob, Read
7
+ steps:
8
+ - steps/shared/step-00-init.md
9
+ - steps/db/step-seed.md
7
10
  ---
8
11
 
9
12
  # EF Core Database Seed Agent
10
13
 
11
14
  Populates the database with test data.
12
15
 
16
+ **Progressive Steps:** Load `steps/db/step-seed.md` for detailed instructions.
17
+
13
18
  ## Workflow
14
19
 
15
20
  1. **Detect** available seeding method:
@@ -5,12 +5,17 @@ color: blue
5
5
  model: haiku
6
6
  tools: Bash, Glob
7
7
  mcp: mcp__smartstack__check_migrations
8
+ steps:
9
+ - steps/shared/step-00-init.md
10
+ - steps/db/step-status.md
8
11
  ---
9
12
 
10
13
  # EF Core Database Status Agent
11
14
 
12
15
  Fast check of EF Core migration state using **SmartStack MCP**.
13
16
 
17
+ **Progressive Steps:** Load `steps/db/step-status.md` for detailed instructions.
18
+
14
19
  ## Workflow
15
20
 
16
21
  1. **Invoke MCP** for migration list and naming validation
@@ -4,12 +4,20 @@ description: EF Core migration manager - orchestrates MCP for naming (1 per feat
4
4
  color: magenta
5
5
  model: sonnet
6
6
  tools: Bash, Glob, Read, Edit
7
+ steps:
8
+ - steps/shared/step-00-init.md
9
+ - steps/migration/step-00-init.md
10
+ - steps/migration/step-01-check.md
11
+ - steps/migration/step-02-create.md
12
+ - steps/migration/step-03-validate.md
7
13
  ---
8
14
 
9
15
  # EF Core Migration Agent
10
16
 
11
17
  Orchestrates migration creation with the "1 migration per feature" rule.
12
18
 
19
+ **Progressive Steps:** Load `steps/migration/` for detailed instructions.
20
+
13
21
  > **IMPORTANT:** Cet agent **ORCHESTRE** uniquement. Le nommage est **DÉLÉGUÉ AU MCP**.
14
22
 
15
23
  > **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.
@@ -4,12 +4,21 @@ description: EF Core snapshot rebaser - resync ModelSnapshot with develop
4
4
  color: yellow
5
5
  model: sonnet
6
6
  tools: Bash, Glob, Read, Edit
7
+ steps:
8
+ - steps/shared/step-00-init.md
9
+ - steps/rebase-snapshot/step-00-init.md
10
+ - steps/rebase-snapshot/step-01-backup.md
11
+ - steps/rebase-snapshot/step-02-fetch.md
12
+ - steps/rebase-snapshot/step-03-create.md
13
+ - steps/rebase-snapshot/step-04-validate.md
7
14
  ---
8
15
 
9
16
  # EF Core Rebase-Snapshot Agent
10
17
 
11
18
  Rebases ModelSnapshot on develop to resolve conflicts.
12
19
 
20
+ **Progressive Steps:** Load `steps/rebase-snapshot/` for detailed instructions.
21
+
13
22
  ## Workflow
14
23
 
15
24
  1. **Backup** all migrations
@@ -21,35 +30,55 @@ Rebases ModelSnapshot on develop to resolve conflicts.
21
30
  ## Key Commands
22
31
 
23
32
  ```bash
33
+ # Détection projet et DbContext
34
+ detect_efcore_project # → $DBCONTEXT, $DBCONTEXT_TYPE, $SCHEMA
35
+ determine_base_branch # → $BASE_BRANCH, $BRANCH_TYPE
36
+
24
37
  # Backup
25
38
  BACKUP_DIR=".claude/gitflow/backup/migrations/rebase_$(date +%Y%m%d_%H%M%S)"
26
39
  mkdir -p "$BACKUP_DIR"
27
40
  cp Migrations/*.cs "$BACKUP_DIR/"
28
41
 
29
- # Reset snapshot to develop
30
- git checkout origin/develop -- Migrations/*ModelSnapshot.cs
42
+ # Reset snapshot to parent branch (develop ou main selon contexte)
43
+ git fetch origin "$BASE_BRANCH"
44
+ git checkout "origin/$BASE_BRANCH" -- Migrations/*ModelSnapshot.cs
45
+
46
+ # Récupérer les migrations de la branche parente
47
+ BASE_MIGS=$(git ls-tree -r --name-only "origin/$BASE_BRANCH" -- Migrations/ | grep "\.cs$" | grep -v "Designer\|Snapshot")
48
+ for base_mig in $BASE_MIGS; do
49
+ base_name=$(basename "${base_mig%.cs}")
50
+ git checkout "origin/$BASE_BRANCH" -- "Migrations/${base_name}.cs" 2>/dev/null || true
51
+ git checkout "origin/$BASE_BRANCH" -- "Migrations/${base_name}.Designer.cs" 2>/dev/null || true
52
+ done
31
53
 
32
- # Delete branch migrations
33
- rm -f Migrations/*Feature_*.cs
34
- rm -f Migrations/*Feature_*.Designer.cs
54
+ # Delete branch migrations only
55
+ rm -f Migrations/*${BRANCH_TYPE}_*.cs
56
+ rm -f Migrations/*${BRANCH_TYPE}_*.Designer.cs
35
57
 
36
- # Regenerate
37
- dotnet ef migrations add Feature_1_7_0_Consolidated
58
+ # Regenerate with MCP naming - OBLIGATOIRE
59
+ mcp__smartstack__suggest_migration({ description: "...", context: DBCONTEXT_TYPE })
60
+ # Résultat: core_v1.7.0_001_UserAuthConsolidated
61
+
62
+ dotnet ef migrations add "$MIGRATION_NAME" --context "$DBCONTEXT"
38
63
 
39
64
  # Validate
40
65
  dotnet build
41
66
  ```
42
67
 
43
- ## Migration Naming
68
+ ## Migration Naming (via MCP)
69
+
70
+ **OBLIGATOIRE : Utiliser le MCP pour le nommage**
44
71
 
45
72
  ```
46
- {Type}_{Version}_{BranchName}_{Description}
73
+ {context}_v{version}_{sequence}_{Description}
47
74
 
48
- Feature_1_7_0_UserAuth_Consolidated
49
- Hotfix_1_6_2_LoginFix_Fix
50
- Release_1_7_0_Initial
75
+ core_v1.7.0_001_UserAuthConsolidated
76
+ core_v1.6.2_001_LoginFixFix
77
+ core_v1.7.0_001_ReleaseInitial
51
78
  ```
52
79
 
80
+ > **INTERDIT :** Pattern ancien `Feature_1_7_0_UserAuth_Consolidated`
81
+
53
82
  ## Safety Checks
54
83
 
55
84
  - [ ] Clean working directory
@@ -4,22 +4,33 @@ description: EF Core migration squasher - combine multiple migrations into one
4
4
  color: magenta
5
5
  model: sonnet
6
6
  tools: Bash, Glob, Read
7
+ steps:
8
+ - steps/shared/step-00-init.md
9
+ - steps/squash/step-00-init.md
10
+ - steps/squash/step-01-backup.md
11
+ - steps/squash/step-02-fetch.md
12
+ - steps/squash/step-03-create.md
13
+ - steps/squash/step-04-validate.md
7
14
  ---
8
15
 
9
16
  # EF Core Squash Agent
10
17
 
11
- Consolide plusieurs migrations en une seule, en récupérant le ModelSnapshot de la branche parente.
18
+ Consolide plusieurs migrations en une seule, en récupérant le ModelSnapshot **ET les migrations** de la branche parente.
19
+
20
+ **Progressive Steps:** Load `steps/squash/` for detailed instructions.
12
21
 
13
22
  ## Principe Fondamental
14
23
 
15
24
  ```
16
- RÈGLE D'OR: Toujours récupérer le snapshot de la branche PARENTE
25
+ RÈGLE D'OR: Récupérer SNAPSHOT + MIGRATIONS de la branche PARENTE
17
26
 
18
- feature/* → snapshot de develop
19
- develop → snapshot de main
20
- release/* → snapshot de main
21
- hotfix/* → snapshot de main
27
+ feature/* → snapshot + migrations de develop
28
+ develop → snapshot + migrations de main
29
+ release/* → snapshot + migrations de main
30
+ hotfix/* → snapshot + migrations de main
22
31
  main → BLOQUÉ (jamais squash)
32
+
33
+ ⚠️ Ne JAMAIS récupérer uniquement le snapshot sans les migrations!
23
34
  ```
24
35
 
25
36
  ## Workflow
@@ -28,36 +39,56 @@ main → BLOQUÉ (jamais squash)
28
39
  2. **List**: Migrations propres à cette branche (pas héritées)
29
40
  3. **Confirm**: Demander validation utilisateur
30
41
  4. **Backup**: Sauvegarder tous les fichiers
31
- 5. **Fetch**: Récupérer ModelSnapshot de branche parente
32
- 6. **Delete**: Supprimer migrations de la branche
33
- 7. **Create**: Créer migration consolidée
42
+ 5. **Fetch**: Récupérer **ModelSnapshot ET migrations** de branche parente (CRUCIAL!)
43
+ 6. **Delete**: Supprimer migrations de la branche UNIQUEMENT
44
+ 7. **Create**: Créer migration consolidée (MCP obligatoire)
34
45
  8. **Validate**: Build + script OK
35
46
 
36
47
  ## Commandes Clés
37
48
 
38
49
  ```bash
39
- # Déterminer branche parente
40
- determine_base_branch # → BASE_BRANCH, BRANCH_TYPE
50
+ # Déterminer branche parente et DbContext
51
+ determine_base_branch # → BASE_BRANCH, BRANCH_TYPE
52
+ detect_efcore_project # → $DBCONTEXT, $DBCONTEXT_TYPE, $SCHEMA
41
53
 
42
54
  # Identifier migrations propres à la branche
43
- BASE_MIGS=$(git ls-tree -r --name-only "origin/$BASE_BRANCH" -- Migrations/)
55
+ BASE_MIGS=$(git ls-tree -r --name-only "origin/$BASE_BRANCH" -- Migrations/ | grep "\.cs$" | grep -v "Designer\|Snapshot")
44
56
  LOCAL_MIGS=$(find Migrations -name "*.cs" | grep -v Designer | grep -v Snapshot)
45
57
 
46
58
  # Backup
47
59
  BACKUP_DIR=".claude/gitflow/backup/migrations/squash_$(date +%Y%m%d_%H%M%S)"
48
60
  mkdir -p "$BACKUP_DIR" && cp Migrations/*.cs "$BACKUP_DIR/"
49
61
 
50
- # CRUCIAL: Récupérer snapshot parent
62
+ # ═══════════════════════════════════════════════════════════════════════════
63
+ # CRUCIAL: Récupérer SNAPSHOT + MIGRATIONS de la branche parente
64
+ # ═══════════════════════════════════════════════════════════════════════════
51
65
  git fetch origin "$BASE_BRANCH"
66
+
67
+ # 1. Récupérer le ModelSnapshot
52
68
  git checkout "origin/$BASE_BRANCH" -- Migrations/*ModelSnapshot.cs
69
+ echo "✅ Snapshot récupéré de origin/$BASE_BRANCH"
70
+
71
+ # 2. Récupérer TOUTES les migrations de la branche parente
72
+ # ⚠️ OBLIGATOIRE: Sans ça, les migrations de develop/main seront perdues!
73
+ for base_mig in $BASE_MIGS; do
74
+ base_name=$(basename "${base_mig%.cs}")
75
+ git checkout "origin/$BASE_BRANCH" -- "Migrations/${base_name}.cs" 2>/dev/null || true
76
+ git checkout "origin/$BASE_BRANCH" -- "Migrations/${base_name}.Designer.cs" 2>/dev/null || true
77
+ echo " ✅ $base_name récupéré"
78
+ done
79
+ echo "✅ $(echo "$BASE_MIGS" | wc -l) migrations récupérées de origin/$BASE_BRANCH"
53
80
 
54
81
  # Supprimer migrations de la branche uniquement
55
82
  for mig in $BRANCH_ONLY_MIGRATIONS; do
56
83
  rm -f "Migrations/${mig}"*
57
84
  done
58
85
 
59
- # Créer migration consolidée
60
- dotnet ef migrations add "${BRANCH_TYPE}_${NAME}_Consolidated"
86
+ # Créer migration consolidée - UTILISER MCP OBLIGATOIRE
87
+ # $DBCONTEXT_TYPE = "core" ou "extensions" (de detect_efcore_project)
88
+ mcp__smartstack__suggest_migration({ description: "...", context: DBCONTEXT_TYPE })
89
+ # Résultat: core_v1.9.0_001_Description
90
+
91
+ dotnet ef migrations add "$MIGRATION_NAME_FROM_MCP" --context "$DBCONTEXT"
61
92
 
62
93
  # Valider
63
94
  dotnet build && dotnet ef migrations script --idempotent > /dev/null
@@ -69,7 +100,9 @@ dotnet build && dotnet ef migrations script --idempotent > /dev/null
69
100
  - [ ] main/master = BLOQUÉ
70
101
  - [ ] User confirmation obtenue
71
102
  - [ ] Backup créé
72
- - [ ] Snapshot parent récupéré
103
+ - [ ] **Snapshot parent récupéré** (origin/$BASE_BRANCH)
104
+ - [ ] **Migrations parent récupérées** (fichiers .cs ET .Designer.cs)
105
+ - [ ] Migrations de la branche supprimées (pas celles héritées!)
73
106
  - [ ] Build OK après squash
74
107
  - [ ] Script générable
75
108
 
@@ -77,9 +110,16 @@ dotnet build && dotnet ef migrations script --idempotent > /dev/null
77
110
 
78
111
  ```
79
112
  SQUASH - {current_branch}
80
- Base: {BASE_BRANCH} (snapshot récupéré)
81
- Avant: {N} migrations (propres à cette branche)
82
- Apres: 1 migration consolidée
113
+ Base: origin/{BASE_BRANCH}
114
+
115
+ Récupéré de {BASE_BRANCH}:
116
+ ✅ ModelSnapshot
117
+ ✅ {N} migrations (fichiers .cs + .Designer.cs)
118
+
119
+ Consolidé:
120
+ Avant: {M} migrations (propres à cette branche)
121
+ Après: 1 migration ({MIGRATION_NAME} via MCP)
122
+
83
123
  Backup: .claude/gitflow/backup/migrations/squash_{timestamp}/
84
124
 
85
125
  Prochains: /efcore:db-reset, /efcore:db-deploy
@@ -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 --json | grep -c '"applied": false')
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 --configuration Release --verbose
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 --project "$INFRA_PROJECT" --startup-project "$STARTUP_PROJECT" --force
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 --project "$INFRA_PROJECT" --startup-project "$STARTUP_PROJECT" --verbose
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
  ---
@@ -12,13 +12,18 @@ model: haiku
12
12
 
13
13
  ---
14
14
 
15
- ## STEP 1: Détecter Configuration
15
+ ## STEP 1: Détecter Configuration et DbContext
16
16
 
17
17
  ```bash
18
- detect_efcore_project
18
+ detect_efcore_project # Appelle detect_dbcontext() automatiquement
19
19
  detect_environment
20
+
21
+ echo "DbContext: $DBCONTEXT ($DBCONTEXT_TYPE)"
22
+ echo "Schema: $SCHEMA"
20
23
  ```
21
24
 
25
+ **Si DbContext non détecté :** Afficher le status des DEUX contextes.
26
+
22
27
  ---
23
28
 
24
29
  ## STEP 2: Invoquer MCP
@@ -26,7 +31,10 @@ detect_environment
26
31
  ```json
27
32
  {
28
33
  "tool": "mcp__smartstack__check_migrations",
29
- "parameters": { "branch": "<current_branch>" }
34
+ "parameters": {
35
+ "branch": "<current_branch>",
36
+ "projectPath": "<auto-detect>"
37
+ }
30
38
  }
31
39
  ```
32
40
 
@@ -37,7 +45,10 @@ Extraire: `migrations[]`, `conflicts[]`
37
45
  ## STEP 3: Tester Connexion
38
46
 
39
47
  ```bash
40
- CONNECTION_OK=$(dotnet ef database list 2>&1)
48
+ CONNECTION_OK=$(dotnet ef database list \
49
+ --context "$DBCONTEXT" \
50
+ --project "$INFRA_PROJECT" \
51
+ --startup-project "$STARTUP_PROJECT" 2>&1)
41
52
  ```
42
53
 
43
54
  ---
@@ -45,8 +56,15 @@ CONNECTION_OK=$(dotnet ef database list 2>&1)
45
56
  ## STEP 4: Compter Migrations
46
57
 
47
58
  ```bash
48
- APPLIED=$(dotnet ef migrations list | grep -v "(Pending)" | wc -l)
49
- PENDING=$(dotnet ef migrations list | grep "(Pending)" | wc -l)
59
+ APPLIED=$(dotnet ef migrations list \
60
+ --context "$DBCONTEXT" \
61
+ --project "$INFRA_PROJECT" \
62
+ --startup-project "$STARTUP_PROJECT" | grep -v "(Pending)" | wc -l)
63
+
64
+ PENDING=$(dotnet ef migrations list \
65
+ --context "$DBCONTEXT" \
66
+ --project "$INFRA_PROJECT" \
67
+ --startup-project "$STARTUP_PROJECT" | grep "(Pending)" | wc -l)
50
68
  ```
51
69
 
52
70
  ---