@atlashub/smartstack-cli 3.36.0 → 3.38.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 +16 -24
- package/dist/index.js.map +1 -1
- package/dist/mcp-entry.mjs +201 -256
- package/dist/mcp-entry.mjs.map +1 -1
- package/package.json +3 -2
- package/scripts/extract-api-endpoints.ts +325 -0
- package/scripts/extract-business-rules.ts +440 -0
- package/scripts/generate-doc-with-mock-ui.ts +804 -0
- package/scripts/health-check.sh +168 -0
- package/scripts/postinstall.js +18 -0
- package/templates/agents/ba-reader.md +9 -9
- package/templates/agents/ba-writer.md +12 -15
- package/templates/agents/code-reviewer.md +1 -1
- package/templates/agents/docs-context-reader.md +1 -1
- package/templates/agents/gitflow/merge.md +0 -4
- package/templates/agents/gitflow/pr.md +0 -4
- package/templates/agents/gitflow/start.md +30 -5
- package/templates/mcp-scaffolding/frontend/nav-routes.ts.hbs +20 -20
- package/templates/mcp-scaffolding/frontend/routes.tsx.hbs +16 -24
- package/templates/mcp-scaffolding/migrations/seed-roles.cs.hbs +2 -2
- package/templates/skills/_resources/mcp-validate-documentation-spec.md +3 -3
- package/templates/skills/_shared.md +15 -17
- package/templates/skills/ai-prompt/SKILL.md +1 -1
- package/templates/skills/ai-prompt/steps/step-00-init.md +47 -0
- package/templates/skills/apex/SKILL.md +3 -4
- package/templates/skills/apex/_shared.md +10 -20
- package/templates/skills/apex/references/analysis-methods.md +141 -0
- package/templates/skills/apex/references/challenge-questions.md +1 -21
- package/templates/skills/apex/references/core-seed-data.md +35 -57
- package/templates/skills/apex/references/examine-build-validation.md +87 -0
- package/templates/skills/apex/references/execution-frontend-gates.md +177 -0
- package/templates/skills/apex/references/execution-frontend-patterns.md +105 -0
- package/templates/skills/apex/references/execution-layer1-rules.md +96 -0
- package/templates/skills/apex/references/initialization-challenge-flow.md +110 -0
- package/templates/skills/apex/references/planning-layer-mapping.md +151 -0
- package/templates/skills/apex/references/post-checks.md +145 -40
- package/templates/skills/apex/references/smartstack-api.md +35 -51
- package/templates/skills/apex/references/smartstack-frontend.md +17 -17
- package/templates/skills/apex/references/smartstack-layers.md +38 -62
- package/templates/skills/apex/steps/step-00-init.md +14 -26
- package/templates/skills/apex/steps/step-01-analyze.md +10 -143
- package/templates/skills/apex/steps/step-02-plan.md +10 -92
- package/templates/skills/apex/steps/step-03-execute.md +47 -249
- package/templates/skills/apex/steps/step-04-examine.md +14 -78
- package/templates/skills/apex/steps/step-05-deep-review.md +2 -2
- package/templates/skills/apex/steps/step-08-run-tests.md +2 -0
- package/templates/skills/application/SKILL.md +6 -7
- package/templates/skills/application/references/backend-controller-hierarchy.md +16 -16
- package/templates/skills/application/references/backend-seeding-and-dto-output.md +83 -0
- package/templates/skills/application/references/backend-table-prefix-mapping.md +79 -0
- package/templates/skills/application/references/backend-verification.md +1 -1
- package/templates/skills/application/references/frontend-i18n-and-output.md +67 -0
- package/templates/skills/application/references/frontend-route-naming.md +117 -0
- package/templates/skills/application/references/frontend-route-wiring-app-tsx.md +107 -0
- package/templates/skills/application/references/frontend-verification.md +12 -12
- package/templates/skills/application/references/init-parameter-detection.md +120 -0
- package/templates/skills/application/references/migration-checklist-troubleshooting.md +100 -0
- package/templates/skills/application/references/nav-fallback-procedure.md +5 -6
- package/templates/skills/application/references/provider-template.md +2 -6
- package/templates/skills/application/references/roles-client-project-handling.md +55 -0
- package/templates/skills/application/references/roles-fallback-procedure.md +149 -0
- package/templates/skills/application/references/test-coverage-requirements.md +213 -0
- package/templates/skills/application/references/test-frontend.md +3 -3
- package/templates/skills/application/steps/step-00-init.md +11 -141
- package/templates/skills/application/steps/step-01-navigation.md +3 -3
- package/templates/skills/application/steps/step-02-permissions.md +4 -4
- package/templates/skills/application/steps/step-03-roles.md +18 -175
- package/templates/skills/application/steps/step-03b-provider.md +1 -2
- package/templates/skills/application/steps/step-04-backend.md +19 -110
- package/templates/skills/application/steps/step-05-frontend.md +17 -143
- package/templates/skills/application/steps/step-06-migration.md +12 -60
- package/templates/skills/application/steps/step-07-tests.md +9 -76
- package/templates/skills/application/templates-backend.md +29 -27
- package/templates/skills/application/templates-frontend.md +48 -48
- package/templates/skills/application/templates-seed.md +57 -131
- package/templates/skills/business-analyse/SKILL.md +27 -30
- package/templates/skills/business-analyse/_architecture.md +6 -6
- package/templates/skills/business-analyse/_shared.md +60 -88
- package/templates/skills/business-analyse/questionnaire/04-data.md +3 -3
- package/templates/skills/business-analyse/questionnaire/06-security.md +1 -1
- package/templates/skills/business-analyse/questionnaire/13-cross-module.md +1 -1
- package/templates/skills/business-analyse/react/application-viewer.md +12 -12
- package/templates/skills/business-analyse/react/components.md +8 -12
- package/templates/skills/business-analyse/react/schema.md +11 -11
- package/templates/skills/business-analyse/references/agent-module-prompt.md +2 -3
- package/templates/skills/business-analyse/references/analysis-semantic-checks.md +190 -0
- package/templates/skills/business-analyse/references/cache-warming-strategy.md +2 -2
- package/templates/skills/business-analyse/references/cadrage-challenge-patterns.md +41 -0
- package/templates/skills/business-analyse/references/cadrage-coverage-matrix.md +74 -0
- package/templates/skills/business-analyse/references/cadrage-shared-modules.md +69 -0
- package/templates/skills/business-analyse/references/cadrage-structure-cards.md +1 -1
- package/templates/skills/business-analyse/references/compilation-structure-cards.md +297 -0
- package/templates/skills/business-analyse/references/consolidation-structural-checks.md +2 -2
- package/templates/skills/business-analyse/references/deploy-modes.md +5 -5
- package/templates/skills/business-analyse/references/detection-strategies.md +7 -7
- package/templates/skills/business-analyse/references/handoff-file-templates.md +14 -22
- package/templates/skills/business-analyse/references/handoff-mappings.md +4 -4
- package/templates/skills/business-analyse/references/handoff-seeddata-generation.md +312 -0
- package/templates/skills/business-analyse/references/init-schema-deployment.md +3 -3
- package/templates/skills/business-analyse/references/naming-conventions.md +22 -24
- package/templates/skills/business-analyse/references/prd-generation.md +2 -2
- package/templates/skills/business-analyse/references/review-data-mapping.md +2 -2
- package/templates/skills/business-analyse/references/robustness-checks.md +1 -1
- package/templates/skills/business-analyse/references/spec-auto-inference.md +3 -3
- package/templates/skills/business-analyse/references/team-orchestration.md +49 -6
- package/templates/skills/business-analyse/references/ui-dashboard-spec.md +1 -1
- package/templates/skills/business-analyse/references/ui-resource-cards.md +18 -18
- package/templates/skills/business-analyse/references/validate-incremental-html.md +2 -2
- package/templates/skills/business-analyse/references/validation-checklist.md +2 -2
- package/templates/skills/business-analyse/schemas/application-schema.json +4 -5
- package/templates/skills/business-analyse/schemas/project-schema.json +1 -6
- package/templates/skills/business-analyse/schemas/sections/metadata-schema.json +2 -3
- package/templates/skills/business-analyse/schemas/sections/specification-schema.json +4 -4
- package/templates/skills/business-analyse/steps/step-00-init.md +8 -17
- package/templates/skills/business-analyse/steps/step-01-cadrage.md +35 -198
- package/templates/skills/business-analyse/steps/step-01b-applications.md +16 -20
- package/templates/skills/business-analyse/steps/step-02-decomposition.md +1 -1
- package/templates/skills/business-analyse/steps/step-03a1-setup.md +4 -4
- package/templates/skills/business-analyse/steps/step-03a2-analysis.md +1 -1
- package/templates/skills/business-analyse/steps/step-03b-ui.md +4 -4
- package/templates/skills/business-analyse/steps/step-03c-compile.md +66 -140
- package/templates/skills/business-analyse/steps/step-03d-validate.md +2 -2
- package/templates/skills/business-analyse/steps/step-04a-collect.md +2 -2
- package/templates/skills/business-analyse/steps/step-04b-analyze.md +42 -160
- package/templates/skills/business-analyse/steps/step-04c-decide.md +1 -1
- package/templates/skills/business-analyse/steps/step-05a-handoff.md +74 -104
- package/templates/skills/business-analyse/steps/step-05b-deploy.md +13 -11
- package/templates/skills/business-analyse/steps/step-06-review.md +3 -3
- package/templates/skills/business-analyse/templates/tpl-frd.md +13 -13
- package/templates/skills/business-analyse/templates/tpl-handoff.md +12 -12
- package/templates/skills/business-analyse/templates-frd.md +25 -25
- package/templates/skills/business-analyse/templates-react.md +15 -21
- package/templates/skills/controller/SKILL.md +1 -1
- package/templates/skills/controller/postman-templates.md +1 -1
- package/templates/skills/controller/references/controller-code-templates.md +2 -2
- package/templates/skills/controller/references/mcp-scaffold-workflow.md +209 -0
- package/templates/skills/controller/references/permission-sync-templates.md +13 -16
- package/templates/skills/controller/steps/step-00-init.md +11 -11
- package/templates/skills/controller/steps/step-03-generate.md +64 -103
- package/templates/skills/controller/templates.md +67 -71
- package/templates/skills/debug/SKILL.md +13 -218
- package/templates/skills/debug/steps/step-00-init.md +57 -0
- package/templates/skills/debug/steps/step-01-analyze.md +219 -0
- package/templates/skills/debug/steps/step-02-resolve.md +85 -0
- package/templates/skills/documentation/SKILL.md +49 -345
- package/templates/skills/documentation/data-schema.md +11 -8
- package/templates/skills/documentation/steps/step-00-init.md +70 -0
- package/templates/skills/documentation/steps/step-01-scan.md +113 -0
- package/templates/skills/documentation/steps/step-02-generate.md +231 -0
- package/templates/skills/documentation/steps/step-03-validate.md +238 -0
- package/templates/skills/documentation/templates.md +480 -322
- package/templates/skills/efcore/references/both-contexts.md +32 -0
- package/templates/skills/efcore/references/database-operations.md +67 -0
- package/templates/skills/efcore/references/destructive-operations.md +38 -0
- package/templates/skills/efcore/references/reset-operations.md +81 -0
- package/templates/skills/efcore/references/seed-methods.md +86 -0
- package/templates/skills/efcore/references/shared-init-functions.md +250 -0
- package/templates/skills/efcore/references/sql-objects-injection.md +61 -0
- package/templates/skills/efcore/references/troubleshooting.md +81 -0
- package/templates/skills/efcore/steps/db/step-deploy.md +1 -32
- package/templates/skills/efcore/steps/db/step-reset.md +7 -103
- package/templates/skills/efcore/steps/db/step-seed.md +10 -132
- package/templates/skills/efcore/steps/db/step-status.md +5 -44
- package/templates/skills/efcore/steps/migration/step-03-validate.md +8 -62
- package/templates/skills/efcore/steps/rebase-snapshot/step-03-create.md +1 -57
- package/templates/skills/efcore/steps/shared/step-00-init.md +11 -254
- package/templates/skills/efcore/steps/squash/step-03-create.md +1 -58
- package/templates/skills/feature-full/SKILL.md +1 -1
- package/templates/skills/feature-full/steps/step-00-init.md +57 -0
- package/templates/skills/feature-full/steps/step-01-implementation.md +1 -1
- package/templates/skills/gitflow/SKILL.md +1 -1
- package/templates/skills/gitflow/_shared.md +23 -0
- package/templates/skills/gitflow/references/commit-message-generation.md +58 -0
- package/templates/skills/gitflow/references/commit-migration-validation.md +49 -0
- package/templates/skills/gitflow/references/finish-cleanup.md +51 -0
- package/templates/skills/gitflow/references/finish-version-bumping.md +45 -0
- package/templates/skills/gitflow/references/init-environment-detection.md +41 -0
- package/templates/skills/gitflow/references/init-questions.md +185 -0
- package/templates/skills/gitflow/references/init-structure-creation.md +71 -0
- package/templates/skills/gitflow/references/init-version-detection.md +21 -0
- package/templates/skills/gitflow/references/init-workspace-detection.md +43 -0
- package/templates/skills/gitflow/references/merge-ci-status.md +36 -0
- package/templates/skills/gitflow/references/merge-execution.md +62 -0
- package/templates/skills/gitflow/references/merge-pr-context.md +76 -0
- package/templates/skills/gitflow/references/pr-build-checks.md +60 -0
- package/templates/skills/gitflow/references/pr-generation.md +58 -0
- package/templates/skills/gitflow/references/start-branch-normalization.md +28 -0
- package/templates/skills/gitflow/references/start-worktree-creation.md +50 -0
- package/templates/skills/gitflow/references/sync-push-verify.md +44 -0
- package/templates/skills/gitflow/references/sync-rebase-conflicts.md +38 -0
- package/templates/skills/gitflow/steps/step-commit.md +12 -91
- package/templates/skills/gitflow/steps/step-finish.md +15 -159
- package/templates/skills/gitflow/steps/step-init.md +24 -326
- package/templates/skills/gitflow/steps/step-merge.md +17 -176
- package/templates/skills/gitflow/steps/step-pr.md +10 -116
- package/templates/skills/gitflow/steps/step-start.md +16 -109
- package/templates/skills/gitflow/steps/step-sync.md +6 -69
- package/templates/skills/ralph-loop/SKILL.md +6 -0
- package/templates/skills/ralph-loop/references/category-completeness.md +185 -0
- package/templates/skills/ralph-loop/references/compact-loop.md +1 -1
- package/templates/skills/ralph-loop/references/init-resume-recovery.md +127 -0
- package/templates/skills/ralph-loop/references/module-transition.md +151 -0
- package/templates/skills/ralph-loop/references/multi-module-queue.md +171 -0
- package/templates/skills/ralph-loop/references/parallel-execution.md +246 -0
- package/templates/skills/ralph-loop/references/task-transform-legacy.md +6 -9
- package/templates/skills/ralph-loop/references/team-orchestration.md +45 -3
- package/templates/skills/ralph-loop/steps/step-00-init.md +36 -109
- package/templates/skills/ralph-loop/steps/step-01-task.md +15 -163
- package/templates/skills/ralph-loop/steps/step-02-execute.md +8 -154
- package/templates/skills/ralph-loop/steps/step-04-check.md +21 -73
- package/templates/skills/review-code/references/owasp-api-top10.md +5 -5
- package/templates/skills/review-code/references/smartstack-conventions.md +11 -11
- package/templates/skills/validate-feature/references/api-smoke-tests.md +140 -0
- package/templates/skills/validate-feature/references/db-validation-checks.md +180 -0
- package/templates/skills/validate-feature/steps/step-01-compile.md +5 -2
- package/templates/skills/validate-feature/steps/step-04-api-smoke.md +34 -145
- package/templates/skills/validate-feature/steps/step-05-db-validation.md +74 -260
- package/templates/skills/workflow/SKILL.md +1 -1
- package/templates/skills/workflow/steps/step-00-init.md +57 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Both Contexts Deployment
|
|
2
|
+
|
|
3
|
+
When `RUN_BOTH=true` (auto-detected for client projects with SmartStack NuGet):
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
# 1. Deploy CoreDbContext first (system tables: Users, Roles, Tenants...)
|
|
7
|
+
echo "=== Deploying CoreDbContext (core schema) ==="
|
|
8
|
+
DBCONTEXT="CoreDbContext"
|
|
9
|
+
SCHEMA="core"
|
|
10
|
+
# Run steps 2-6 with CoreDbContext...
|
|
11
|
+
|
|
12
|
+
dotnet ef database update \
|
|
13
|
+
--context "CoreDbContext" \
|
|
14
|
+
--project "$INFRA_PROJECT" \
|
|
15
|
+
--startup-project "$STARTUP_PROJECT" \
|
|
16
|
+
--verbose
|
|
17
|
+
|
|
18
|
+
# 2. Then ExtensionsDbContext (client tables)
|
|
19
|
+
echo ""
|
|
20
|
+
echo "=== Deploying ExtensionsDbContext (extensions schema) ==="
|
|
21
|
+
DBCONTEXT="ExtensionsDbContext"
|
|
22
|
+
SCHEMA="extensions"
|
|
23
|
+
# Run steps 2-6 with ExtensionsDbContext...
|
|
24
|
+
|
|
25
|
+
dotnet ef database update \
|
|
26
|
+
--context "ExtensionsDbContext" \
|
|
27
|
+
--project "$INFRA_PROJECT" \
|
|
28
|
+
--startup-project "$STARTUP_PROJECT" \
|
|
29
|
+
--verbose
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Order matters:** Core MUST be deployed first (Extensions may have foreign keys to Core tables).
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Database Operations
|
|
2
|
+
|
|
3
|
+
## Common Validation Checks
|
|
4
|
+
|
|
5
|
+
### Check Required Variables
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Validate required variables from step-00-init
|
|
9
|
+
for VAR_NAME in DBCONTEXT DBCONTEXT_TYPE INFRA_PROJECT STARTUP_PROJECT SELECTED_ENV; do
|
|
10
|
+
eval VAR_VALUE=\$$VAR_NAME
|
|
11
|
+
if [ -z "$VAR_VALUE" ]; then
|
|
12
|
+
echo "ERROR: Required variable $VAR_NAME is not set"
|
|
13
|
+
echo "Run step-00-init first"
|
|
14
|
+
exit 1
|
|
15
|
+
fi
|
|
16
|
+
done
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Backup Command
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
BACKUP_DIR=".claude/gitflow/backup/database"
|
|
23
|
+
mkdir -p "$BACKUP_DIR"
|
|
24
|
+
|
|
25
|
+
BACKUP_FILE="$BACKUP_DIR/${DATABASE_NAME}_$(date +%Y%m%d_%H%M%S).bak"
|
|
26
|
+
|
|
27
|
+
echo "Creating backup: $BACKUP_FILE"
|
|
28
|
+
|
|
29
|
+
sqlcmd -S "$SERVER_NAME" -E -Q "BACKUP DATABASE [$DATABASE_NAME] TO DISK='$BACKUP_FILE'"
|
|
30
|
+
|
|
31
|
+
if [ $? -eq 0 ]; then
|
|
32
|
+
echo "Backup created: $BACKUP_FILE"
|
|
33
|
+
else
|
|
34
|
+
echo "WARNING: Backup failed. Continue anyway?"
|
|
35
|
+
fi
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Connection Test
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
CONNECTION_TEST=$(dotnet ef database list \
|
|
42
|
+
--context "$DBCONTEXT" \
|
|
43
|
+
--project "$INFRA_PROJECT" \
|
|
44
|
+
--startup-project "$STARTUP_PROJECT" 2>&1)
|
|
45
|
+
|
|
46
|
+
if [ $? -eq 0 ]; then
|
|
47
|
+
echo "Connection: OK"
|
|
48
|
+
else
|
|
49
|
+
echo "Connection: FAILED"
|
|
50
|
+
echo ""
|
|
51
|
+
echo "$CONNECTION_TEST"
|
|
52
|
+
fi
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Migration Count Utilities
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Count applied and pending
|
|
59
|
+
MIGRATION_OUTPUT=$(dotnet ef migrations list \
|
|
60
|
+
--context "$DBCONTEXT" \
|
|
61
|
+
--project "$INFRA_PROJECT" \
|
|
62
|
+
--startup-project "$STARTUP_PROJECT" 2>/dev/null)
|
|
63
|
+
|
|
64
|
+
APPLIED=$(echo "$MIGRATION_OUTPUT" | grep -v "(Pending)" | grep -c "^[0-9]" || echo "0")
|
|
65
|
+
PENDING=$(echo "$MIGRATION_OUTPUT" | grep -c "(Pending)" || echo "0")
|
|
66
|
+
TOTAL=$((APPLIED + PENDING))
|
|
67
|
+
```
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Destructive Operations & Zero-Downtime Patterns
|
|
2
|
+
|
|
3
|
+
When a migration contains destructive operations (DropColumn, RenameColumn, AlterColumn, DropTable), consider zero-downtime patterns for production deployments.
|
|
4
|
+
|
|
5
|
+
## Detection
|
|
6
|
+
|
|
7
|
+
Migration Analysis counts:
|
|
8
|
+
- DropColumn
|
|
9
|
+
- RenameColumn
|
|
10
|
+
- AlterColumn
|
|
11
|
+
- DropTable
|
|
12
|
+
|
|
13
|
+
If any count > 0, display warning and reference this document.
|
|
14
|
+
|
|
15
|
+
## Zero-Downtime Patterns
|
|
16
|
+
|
|
17
|
+
For production deployments with destructive operations:
|
|
18
|
+
|
|
19
|
+
1. **Add → Populate → Migrate → Remove** (for column renames)
|
|
20
|
+
- Add new column
|
|
21
|
+
- Populate from old column
|
|
22
|
+
- Deploy migration
|
|
23
|
+
- Remove old column in next deployment window
|
|
24
|
+
|
|
25
|
+
2. **Feature Flags** (for table changes)
|
|
26
|
+
- Add feature flag
|
|
27
|
+
- Deploy new code path
|
|
28
|
+
- Migrate data
|
|
29
|
+
- Remove old code path after stabilization
|
|
30
|
+
|
|
31
|
+
3. **Gradual Rollout**
|
|
32
|
+
- Deploy to staging first
|
|
33
|
+
- Monitor for issues
|
|
34
|
+
- Gradually roll to production clusters
|
|
35
|
+
|
|
36
|
+
## Reference
|
|
37
|
+
|
|
38
|
+
See OWASP and database migration best practices for your platform.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Database Reset Operations
|
|
2
|
+
|
|
3
|
+
## Drop Database
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
echo ""
|
|
7
|
+
echo "Dropping database..."
|
|
8
|
+
|
|
9
|
+
dotnet ef database drop \
|
|
10
|
+
--context "$DBCONTEXT" \
|
|
11
|
+
--project "$INFRA_PROJECT" \
|
|
12
|
+
--startup-project "$STARTUP_PROJECT" \
|
|
13
|
+
--force
|
|
14
|
+
EXIT_CODE=$?
|
|
15
|
+
|
|
16
|
+
if [ $EXIT_CODE -ne 0 ]; then
|
|
17
|
+
echo "ERROR: Drop failed (exit code: $EXIT_CODE)"
|
|
18
|
+
echo "Database may be in use. Close connections and retry."
|
|
19
|
+
exit 1
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
echo "Database dropped."
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Recreate + Apply Migrations
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
echo ""
|
|
29
|
+
echo "Recreating database with migrations..."
|
|
30
|
+
|
|
31
|
+
dotnet ef database update \
|
|
32
|
+
--context "$DBCONTEXT" \
|
|
33
|
+
--project "$INFRA_PROJECT" \
|
|
34
|
+
--startup-project "$STARTUP_PROJECT" \
|
|
35
|
+
--verbose
|
|
36
|
+
EXIT_CODE=$?
|
|
37
|
+
|
|
38
|
+
if [ $EXIT_CODE -ne 0 ]; then
|
|
39
|
+
echo ""
|
|
40
|
+
echo "ERROR: Recreation failed (exit code: $EXIT_CODE)"
|
|
41
|
+
exit 1
|
|
42
|
+
fi
|
|
43
|
+
|
|
44
|
+
echo "Database recreated."
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Summary After Reset
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
MIGRATION_COUNT=$(dotnet ef migrations list \
|
|
51
|
+
--context "$DBCONTEXT" \
|
|
52
|
+
--project "$INFRA_PROJECT" \
|
|
53
|
+
--startup-project "$STARTUP_PROJECT" 2>/dev/null | \
|
|
54
|
+
grep -c "^[0-9]" || echo "0")
|
|
55
|
+
|
|
56
|
+
echo ""
|
|
57
|
+
echo "==========================================="
|
|
58
|
+
echo "RESET COMPLETE"
|
|
59
|
+
echo "==========================================="
|
|
60
|
+
echo ""
|
|
61
|
+
echo "Database: $DATABASE_NAME"
|
|
62
|
+
echo "Environment: $SELECTED_ENV"
|
|
63
|
+
echo "DbContext: $DBCONTEXT"
|
|
64
|
+
echo ""
|
|
65
|
+
echo "Operations:"
|
|
66
|
+
echo " - Drop: OK"
|
|
67
|
+
echo " - Create: OK"
|
|
68
|
+
echo " - Migrations: $MIGRATION_COUNT applied"
|
|
69
|
+
if [ -n "$BACKUP_FILE" ]; then
|
|
70
|
+
echo " - Backup: $BACKUP_FILE"
|
|
71
|
+
fi
|
|
72
|
+
echo ""
|
|
73
|
+
echo "Compliance: EF Core CLI only"
|
|
74
|
+
echo ""
|
|
75
|
+
echo "==========================================="
|
|
76
|
+
echo ""
|
|
77
|
+
echo "Next steps:"
|
|
78
|
+
echo " /efcore db-status # Verify status"
|
|
79
|
+
echo " /efcore db-seed # Add test data"
|
|
80
|
+
echo ""
|
|
81
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Seed Methods Detection & Execution
|
|
2
|
+
|
|
3
|
+
## Detect Available Seed Methods
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
echo ""
|
|
7
|
+
echo "Detecting seed methods..."
|
|
8
|
+
|
|
9
|
+
SEED_METHODS=""
|
|
10
|
+
|
|
11
|
+
# HasData() in configurations (RECOMMENDED)
|
|
12
|
+
if grep -rq "\.HasData(" . --include="*.cs" 2>/dev/null; then
|
|
13
|
+
SEED_METHODS+=" hasdata"
|
|
14
|
+
echo " - HasData(): Found"
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
# IDataSeeder classes
|
|
18
|
+
if grep -rq "IDataSeeder\|class.*Seeder" . --include="*.cs" 2>/dev/null; then
|
|
19
|
+
SEED_METHODS+=" seeder-class"
|
|
20
|
+
echo " - Seeder classes: Found"
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
# --seed CLI argument
|
|
24
|
+
if grep -q "\-\-seed" ./src/*/Program.cs 2>/dev/null; then
|
|
25
|
+
SEED_METHODS+=" cli-argument"
|
|
26
|
+
echo " - CLI --seed: Found"
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# WARNING: SQL scripts detected
|
|
30
|
+
if [ -f "./scripts/seed.sql" ] || find . -name "seed*.sql" 2>/dev/null | grep -q .; then
|
|
31
|
+
echo ""
|
|
32
|
+
echo "WARNING: SQL seed scripts detected - FORBIDDEN by conventions"
|
|
33
|
+
echo "Migrate to HasData() or IDataSeeder"
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
if [ -z "$SEED_METHODS" ]; then
|
|
37
|
+
echo " No seed methods found"
|
|
38
|
+
fi
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Execute Seed - HasData
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
echo ""
|
|
45
|
+
echo "HasData is applied via migrations."
|
|
46
|
+
echo "Running database update to ensure all HasData is applied..."
|
|
47
|
+
|
|
48
|
+
dotnet ef database update \
|
|
49
|
+
--context "$DBCONTEXT" \
|
|
50
|
+
--project "$INFRA_PROJECT" \
|
|
51
|
+
--startup-project "$STARTUP_PROJECT"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Execute Seed - Seeder Class
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
echo ""
|
|
58
|
+
echo "Running seeder class..."
|
|
59
|
+
|
|
60
|
+
dotnet run --project "$STARTUP_PROJECT" -- --seed
|
|
61
|
+
EXIT_CODE=$?
|
|
62
|
+
|
|
63
|
+
if [ $EXIT_CODE -ne 0 ]; then
|
|
64
|
+
echo "Seed command failed or not supported (exit code: $EXIT_CODE)"
|
|
65
|
+
echo "Check if --seed argument is implemented in Program.cs"
|
|
66
|
+
fi
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Execute Seed - CLI Argument
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
echo ""
|
|
73
|
+
echo "Running application with --seed..."
|
|
74
|
+
|
|
75
|
+
dotnet run --project "$STARTUP_PROJECT" -- --seed
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Verify Seed Data
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
echo ""
|
|
82
|
+
echo "Verifying seed data..."
|
|
83
|
+
|
|
84
|
+
# Quick check - count records in key tables
|
|
85
|
+
# This is application-specific
|
|
86
|
+
```
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
# Shared Initialization Functions
|
|
2
|
+
|
|
3
|
+
## Ensure dotnet ef Available (Platform-Aware)
|
|
4
|
+
|
|
5
|
+
**CRITICAL:** On Windows (Git Bash, MSYS2), `dotnet ef` may not be on the shell PATH
|
|
6
|
+
even though it's installed. This function fixes PATH before any EF Core command.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
ensure_dotnet_ef() {
|
|
10
|
+
# Quick check: already available?
|
|
11
|
+
if dotnet ef --version &>/dev/null; then
|
|
12
|
+
DOTNET_EF_VERSION=$(dotnet ef --version 2>/dev/null)
|
|
13
|
+
echo "dotnet-ef: $DOTNET_EF_VERSION"
|
|
14
|
+
return 0
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
echo "dotnet-ef not on PATH, attempting platform-aware fix..."
|
|
18
|
+
|
|
19
|
+
# Try all known .NET global tools locations
|
|
20
|
+
# - $USERPROFILE/.dotnet/tools → Windows via Git Bash (USERPROFILE=C:\Users\xxx)
|
|
21
|
+
# - $HOME/.dotnet/tools → Linux/macOS or Git Bash fallback
|
|
22
|
+
# - $LOCALAPPDATA/Microsoft/dotnet/tools → Windows alternate location
|
|
23
|
+
for TOOLS_DIR in \
|
|
24
|
+
"$USERPROFILE/.dotnet/tools" \
|
|
25
|
+
"$HOME/.dotnet/tools" \
|
|
26
|
+
"$LOCALAPPDATA/Microsoft/dotnet/tools"; do
|
|
27
|
+
if [ -n "$TOOLS_DIR" ] && [ -d "$TOOLS_DIR" ]; then
|
|
28
|
+
export PATH="$TOOLS_DIR:$PATH"
|
|
29
|
+
echo " PATH += $TOOLS_DIR"
|
|
30
|
+
fi
|
|
31
|
+
done
|
|
32
|
+
|
|
33
|
+
# Verify after PATH fix
|
|
34
|
+
if dotnet ef --version &>/dev/null; then
|
|
35
|
+
DOTNET_EF_VERSION=$(dotnet ef --version 2>/dev/null)
|
|
36
|
+
echo "dotnet-ef: $DOTNET_EF_VERSION (found after PATH fix)"
|
|
37
|
+
return 0
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
echo "ERROR: dotnet-ef not available"
|
|
41
|
+
echo "Install with: dotnet tool install --global dotnet-ef"
|
|
42
|
+
echo ""
|
|
43
|
+
echo "If installed but not found, check:"
|
|
44
|
+
echo " Windows: %USERPROFILE%\\.dotnet\\tools must be in PATH"
|
|
45
|
+
echo " Linux: ~/.dotnet/tools must be in PATH"
|
|
46
|
+
exit 1
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
ensure_dotnet_ef
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**IMPORTANT — WSL pitfall:**
|
|
53
|
+
If the shell resolves `$HOME` to `/home/{user}` (WSL path) instead of `/c/Users/{user}` (Git Bash),
|
|
54
|
+
the .NET SDK may not be found even if `dotnet-ef` is. Use `$USERPROFILE` first on Windows.
|
|
55
|
+
|
|
56
|
+
## Detect EF Core Project
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
detect_efcore_project() {
|
|
60
|
+
# Find project with EF Core reference
|
|
61
|
+
CSPROJ=$(find . -name "*.csproj" -exec grep -l "Microsoft.EntityFrameworkCore" {} \; | head -1)
|
|
62
|
+
|
|
63
|
+
if [ -z "$CSPROJ" ]; then
|
|
64
|
+
echo "ERROR: No EF Core project found"
|
|
65
|
+
exit 1
|
|
66
|
+
fi
|
|
67
|
+
|
|
68
|
+
PROJECT_DIR=$(dirname "$CSPROJ")
|
|
69
|
+
PROJECT_NAME=$(basename "$CSPROJ" .csproj)
|
|
70
|
+
MIGRATIONS_DIR="$PROJECT_DIR/Persistence/Migrations"
|
|
71
|
+
|
|
72
|
+
# Find startup and infrastructure projects
|
|
73
|
+
STARTUP_PROJECT=$(find . -name "*.Api.csproj" -o -name "*Web.csproj" | head -1)
|
|
74
|
+
INFRA_PROJECT=$(find . -name "*Infrastructure.csproj" | head -1)
|
|
75
|
+
[ -z "$INFRA_PROJECT" ] && INFRA_PROJECT="$CSPROJ"
|
|
76
|
+
|
|
77
|
+
echo "Project: $PROJECT_NAME"
|
|
78
|
+
echo "Migrations: $MIGRATIONS_DIR"
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Detect DbContext (Core vs Extensions)
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
detect_dbcontext() {
|
|
86
|
+
# Priority 1: SmartStack.Domain exists → SmartStack source project (Core only)
|
|
87
|
+
if find . -type d -name "SmartStack.Domain" | grep -q .; then
|
|
88
|
+
DBCONTEXT="CoreDbContext"
|
|
89
|
+
DBCONTEXT_TYPE="core"
|
|
90
|
+
SCHEMA="core"
|
|
91
|
+
RUN_BOTH=false
|
|
92
|
+
echo "DbContext: CoreDbContext (SmartStack.Domain found)"
|
|
93
|
+
return
|
|
94
|
+
fi
|
|
95
|
+
|
|
96
|
+
# Priority 2: Client project with SmartStack NuGet → BOTH contexts
|
|
97
|
+
if find . -name "*.csproj" -exec grep -ql "PackageReference.*SmartStack" {} \; 2>/dev/null; then
|
|
98
|
+
DBCONTEXT="CoreDbContext"
|
|
99
|
+
DBCONTEXT_TYPE="both"
|
|
100
|
+
SCHEMA="core"
|
|
101
|
+
RUN_BOTH=true
|
|
102
|
+
echo "DbContext: Both (Core from SmartStack NuGet + Extensions local)"
|
|
103
|
+
echo " Deploy order: CoreDbContext → ExtensionsDbContext"
|
|
104
|
+
return
|
|
105
|
+
fi
|
|
106
|
+
|
|
107
|
+
# Priority 3: Scan for DbContext in code
|
|
108
|
+
CORE_CTX=$(find . -name "*.cs" -exec grep -l "CoreDbContext" {} \; 2>/dev/null | head -1)
|
|
109
|
+
EXT_CTX=$(find . -name "*.cs" -exec grep -l "ExtensionsDbContext" {} \; 2>/dev/null | head -1)
|
|
110
|
+
|
|
111
|
+
if [ -n "$CORE_CTX" ] && [ -n "$EXT_CTX" ]; then
|
|
112
|
+
DBCONTEXT="CoreDbContext"
|
|
113
|
+
DBCONTEXT_TYPE="both"
|
|
114
|
+
SCHEMA="core"
|
|
115
|
+
RUN_BOTH=true
|
|
116
|
+
echo "DbContext: Both (CoreDbContext + ExtensionsDbContext found)"
|
|
117
|
+
elif [ -n "$CORE_CTX" ] && [ -z "$EXT_CTX" ]; then
|
|
118
|
+
DBCONTEXT="CoreDbContext"
|
|
119
|
+
DBCONTEXT_TYPE="core"
|
|
120
|
+
SCHEMA="core"
|
|
121
|
+
RUN_BOTH=false
|
|
122
|
+
elif [ -z "$CORE_CTX" ] && [ -n "$EXT_CTX" ]; then
|
|
123
|
+
DBCONTEXT="ExtensionsDbContext"
|
|
124
|
+
DBCONTEXT_TYPE="extensions"
|
|
125
|
+
SCHEMA="extensions"
|
|
126
|
+
RUN_BOTH=false
|
|
127
|
+
else
|
|
128
|
+
DBCONTEXT=""
|
|
129
|
+
DBCONTEXT_TYPE=""
|
|
130
|
+
SCHEMA=""
|
|
131
|
+
RUN_BOTH=false
|
|
132
|
+
fi
|
|
133
|
+
}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Detect Environment
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
detect_environment() {
|
|
140
|
+
API_DIR=$(find . -type d -name "*.Api" | head -1)
|
|
141
|
+
[ -z "$API_DIR" ] && API_DIR="src/SmartStack.Api"
|
|
142
|
+
|
|
143
|
+
# Priority: --env flag > appsettings.Local.json > error
|
|
144
|
+
if [ -n "$ENV_FLAG" ]; then
|
|
145
|
+
CONFIG_FILE="$API_DIR/appsettings.${ENV_FLAG}.json"
|
|
146
|
+
elif [ -f "$API_DIR/appsettings.Local.json" ]; then
|
|
147
|
+
CONFIG_FILE="$API_DIR/appsettings.Local.json"
|
|
148
|
+
SELECTED_ENV="Local"
|
|
149
|
+
else
|
|
150
|
+
echo "ERROR: No appsettings.Local.json found"
|
|
151
|
+
echo "Create one or use --env flag"
|
|
152
|
+
exit 1
|
|
153
|
+
fi
|
|
154
|
+
|
|
155
|
+
echo "Environment: $SELECTED_ENV"
|
|
156
|
+
echo "Config: $CONFIG_FILE"
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Determine Base Branch
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
determine_base_branch() {
|
|
164
|
+
CURRENT_BRANCH=$(git branch --show-current)
|
|
165
|
+
|
|
166
|
+
case "$CURRENT_BRANCH" in
|
|
167
|
+
feature/*)
|
|
168
|
+
BASE_BRANCH="develop"
|
|
169
|
+
BRANCH_TYPE="feature"
|
|
170
|
+
;;
|
|
171
|
+
release/*)
|
|
172
|
+
BASE_BRANCH="main"
|
|
173
|
+
BRANCH_TYPE="release"
|
|
174
|
+
;;
|
|
175
|
+
hotfix/*)
|
|
176
|
+
BASE_BRANCH="main"
|
|
177
|
+
BRANCH_TYPE="hotfix"
|
|
178
|
+
;;
|
|
179
|
+
develop)
|
|
180
|
+
BASE_BRANCH="main"
|
|
181
|
+
BRANCH_TYPE="develop"
|
|
182
|
+
;;
|
|
183
|
+
main|master)
|
|
184
|
+
echo "ERROR: Cannot run on main/master branch"
|
|
185
|
+
exit 1
|
|
186
|
+
;;
|
|
187
|
+
*)
|
|
188
|
+
BASE_BRANCH="develop"
|
|
189
|
+
BRANCH_TYPE="unknown"
|
|
190
|
+
;;
|
|
191
|
+
esac
|
|
192
|
+
|
|
193
|
+
echo "Branch: $CURRENT_BRANCH ($BRANCH_TYPE)"
|
|
194
|
+
echo "Base: $BASE_BRANCH"
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Block Production
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
block_production() {
|
|
202
|
+
# Check for production indicators (case-insensitive)
|
|
203
|
+
if grep -qi '"Production"' "$CONFIG_FILE" 2>/dev/null; then
|
|
204
|
+
echo "BLOCKED: Production environment detected in $CONFIG_FILE"
|
|
205
|
+
exit 1
|
|
206
|
+
fi
|
|
207
|
+
|
|
208
|
+
# Case-insensitive database name check
|
|
209
|
+
DB_LOWER=$(echo "$DATABASE_NAME" | tr '[:upper:]' '[:lower:]')
|
|
210
|
+
if [[ "$DB_LOWER" == *"prod"* ]] || [[ "$DB_LOWER" == *"production"* ]]; then
|
|
211
|
+
echo "BLOCKED: Production database detected ($DATABASE_NAME)"
|
|
212
|
+
exit 1
|
|
213
|
+
fi
|
|
214
|
+
|
|
215
|
+
# Environment name check (case-insensitive)
|
|
216
|
+
ENV_LOWER=$(echo "$SELECTED_ENV" | tr '[:upper:]' '[:lower:]')
|
|
217
|
+
if [[ "$ENV_LOWER" == "production" ]] || [[ "$ENV_LOWER" == "prod" ]]; then
|
|
218
|
+
echo "BLOCKED: Production environment selected ($SELECTED_ENV)"
|
|
219
|
+
exit 1
|
|
220
|
+
fi
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Dual Context Helper
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
# Helper for steps that need to run for both contexts when RUN_BOTH=true
|
|
228
|
+
# Usage: run_for_contexts "command_or_function"
|
|
229
|
+
# Executes with CoreDbContext first, then ExtensionsDbContext
|
|
230
|
+
# Maintains deploy order constraint: Core MUST run first
|
|
231
|
+
|
|
232
|
+
run_for_contexts() {
|
|
233
|
+
if [ "$RUN_BOTH" = "true" ]; then
|
|
234
|
+
echo "=== Running for CoreDbContext (core schema) ==="
|
|
235
|
+
DBCONTEXT="CoreDbContext"
|
|
236
|
+
DBCONTEXT_TYPE="core"
|
|
237
|
+
SCHEMA="core"
|
|
238
|
+
eval "$1"
|
|
239
|
+
|
|
240
|
+
echo ""
|
|
241
|
+
echo "=== Running for ExtensionsDbContext (extensions schema) ==="
|
|
242
|
+
DBCONTEXT="ExtensionsDbContext"
|
|
243
|
+
DBCONTEXT_TYPE="extensions"
|
|
244
|
+
SCHEMA="extensions"
|
|
245
|
+
eval "$1"
|
|
246
|
+
else
|
|
247
|
+
eval "$1"
|
|
248
|
+
fi
|
|
249
|
+
}
|
|
250
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# SQL Objects Injection
|
|
2
|
+
|
|
3
|
+
EF Core does NOT generate DDL for TVF, views, and stored procedures.
|
|
4
|
+
SQL source scripts are in `Persistence/SqlObjects/` (Embedded Resources).
|
|
5
|
+
After a migration/squash/rebase, they must be re-injected into the consolidated migration.
|
|
6
|
+
|
|
7
|
+
## Injection Process
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Check if SqlObjects folder exists with .sql files
|
|
11
|
+
SQL_OBJECTS_DIR="$INFRA_PROJECT_DIR/Persistence/SqlObjects"
|
|
12
|
+
SQL_FILES=$(find "$SQL_OBJECTS_DIR" -name "*.sql" 2>/dev/null | wc -l)
|
|
13
|
+
|
|
14
|
+
if [ "$SQL_FILES" -gt 0 ]; then
|
|
15
|
+
echo ""
|
|
16
|
+
echo "Found $SQL_FILES SQL object(s) in SqlObjects/"
|
|
17
|
+
echo "Injecting SqlObjectHelper.ApplyAll(migrationBuilder) into migration..."
|
|
18
|
+
|
|
19
|
+
# Validate migration file path before sed operations
|
|
20
|
+
if [ ! -f "$MIGRATION_FILE" ]; then
|
|
21
|
+
echo "ERROR: Migration file not found: $MIGRATION_FILE"
|
|
22
|
+
exit 1
|
|
23
|
+
fi
|
|
24
|
+
if ! echo "$MIGRATION_FILE" | grep -qE '\.cs$'; then
|
|
25
|
+
echo "ERROR: Invalid migration file path (not .cs): $MIGRATION_FILE"
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
# Add using directive if not present
|
|
30
|
+
if ! grep -q "using SmartStack.Infrastructure.Persistence.SqlObjects;" "$MIGRATION_FILE"; then
|
|
31
|
+
sed -i '1s/^/using SmartStack.Infrastructure.Persistence.SqlObjects;\n/' "$MIGRATION_FILE"
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
# Add SqlObjectHelper.ApplyAll at the end of Up() method
|
|
35
|
+
sed -i '/protected override void Up/,/^ }/ {
|
|
36
|
+
/^ }/ i\
|
|
37
|
+
\ // Apply SQL objects (TVF, Views, SP) from embedded resources\
|
|
38
|
+
\ SqlObjectHelper.ApplyAll(migrationBuilder);
|
|
39
|
+
}' "$MIGRATION_FILE"
|
|
40
|
+
|
|
41
|
+
# Verify injection succeeded (fallback to manual step if sed pattern didn't match)
|
|
42
|
+
if ! grep -q "SqlObjectHelper.ApplyAll" "$MIGRATION_FILE"; then
|
|
43
|
+
echo "WARNING: Automatic injection failed (indentation pattern may differ)"
|
|
44
|
+
echo ""
|
|
45
|
+
echo "MANUAL STEP REQUIRED: Add these lines inside the Up() method before the closing brace:"
|
|
46
|
+
echo ' using SmartStack.Infrastructure.Persistence.SqlObjects;'
|
|
47
|
+
echo ' ...'
|
|
48
|
+
echo ' SqlObjectHelper.ApplyAll(migrationBuilder);'
|
|
49
|
+
echo ""
|
|
50
|
+
echo "File: $MIGRATION_FILE"
|
|
51
|
+
else
|
|
52
|
+
echo " SqlObjectHelper.ApplyAll(migrationBuilder) injected"
|
|
53
|
+
fi
|
|
54
|
+
find "$SQL_OBJECTS_DIR" -name "*.sql" -exec basename {} \; | while read f; do
|
|
55
|
+
echo " - $f"
|
|
56
|
+
done
|
|
57
|
+
else
|
|
58
|
+
echo ""
|
|
59
|
+
echo "No SQL objects found in SqlObjects/ - skipping injection"
|
|
60
|
+
fi
|
|
61
|
+
```
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# EF Core Troubleshooting
|
|
2
|
+
|
|
3
|
+
## Database Status
|
|
4
|
+
|
|
5
|
+
### Troubleshooting (if connection fails)
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
TROUBLESHOOTING
|
|
9
|
+
├── SQL Server running?
|
|
10
|
+
├── appsettings.Local.json configured?
|
|
11
|
+
├── Database exists?
|
|
12
|
+
└── Commands: /efcore db-reset, /efcore db-deploy
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Deploy Errors
|
|
16
|
+
|
|
17
|
+
| Error | Resolution |
|
|
18
|
+
|-------|------------|
|
|
19
|
+
| Connection failed | Check SQL Server, credentials |
|
|
20
|
+
| Migration error | Review migration, consider reset |
|
|
21
|
+
| Constraint violation | Check data, may need seed |
|
|
22
|
+
|
|
23
|
+
## Reset Protections
|
|
24
|
+
|
|
25
|
+
| Protection | Description |
|
|
26
|
+
|------------|-------------|
|
|
27
|
+
| Env Display | Shows database BEFORE confirmation |
|
|
28
|
+
| Confirmation | Explicit request with database NAME |
|
|
29
|
+
| Production Block | Blocks if Production detected |
|
|
30
|
+
| EF Core Only | No raw SQL |
|
|
31
|
+
|
|
32
|
+
## Seed Setup Guide
|
|
33
|
+
|
|
34
|
+
If no seed methods detected, display guide:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
SEED SETUP GUIDE
|
|
38
|
+
================
|
|
39
|
+
|
|
40
|
+
Option 1: HasData() in Configuration (RECOMMENDED)
|
|
41
|
+
--------------------------------------------------
|
|
42
|
+
// In UserConfiguration.cs
|
|
43
|
+
builder.HasData(new User {
|
|
44
|
+
Id = Guid.Parse("7f3c9a2e-8d1b-4e5f-a6c8-9b4d2f7e1a3c"),
|
|
45
|
+
Name = "Admin",
|
|
46
|
+
Email = "admin@example.com"
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Then run:
|
|
50
|
+
dotnet ef migrations add SeedData
|
|
51
|
+
|
|
52
|
+
Option 2: IDataSeeder Class
|
|
53
|
+
---------------------------
|
|
54
|
+
public class UserSeeder : IDataSeeder
|
|
55
|
+
{
|
|
56
|
+
public async Task SeedAsync(DbContext context)
|
|
57
|
+
{
|
|
58
|
+
if (!await context.Users.AnyAsync())
|
|
59
|
+
{
|
|
60
|
+
context.Users.Add(new User { ... });
|
|
61
|
+
await context.SaveChangesAsync();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Register in Program.cs and call via --seed argument
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Migration from SQL
|
|
70
|
+
|
|
71
|
+
```csharp
|
|
72
|
+
// BEFORE (FORBIDDEN): scripts/seed.sql
|
|
73
|
+
INSERT INTO Users (Id, Name) VALUES (1, 'Admin');
|
|
74
|
+
|
|
75
|
+
// AFTER (CORRECT): UserConfiguration.cs
|
|
76
|
+
builder.HasData(new User {
|
|
77
|
+
Id = Guid.Parse("7f3c9a2e-8d1b-4e5f-a6c8-9b4d2f7e1a3c"),
|
|
78
|
+
Name = "Admin"
|
|
79
|
+
});
|
|
80
|
+
// Then: dotnet ef migrations add SeedData
|
|
81
|
+
```
|