Repository navigation
fix: harden deploy pre-rollout DB drift guardrails - #197
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for regal-bunny-0c8efe ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a shared database relations verifier used during deploy-time validation. Requires prisma migrate status check before service restart. Enforces verification of four required database tables (guild_role_grants, guild_automation_manifests, guild_automation_runs, guild_automation_drifts). Unifies verification logic and strengthens pre-flight deployment validation. Changes
Sequence DiagramsequenceDiagram
participant Deploy as Deploy Script
participant Prisma as Prisma Migrate
participant DB as Database
participant Guard as Relation Guard
participant Services as Runtime Services
participant Notify as Notification
Deploy->>Prisma: prisma migrate deploy
Prisma->>DB: Apply pending migrations
DB-->>Prisma: Done
Prisma-->>Deploy: Success
Deploy->>Prisma: prisma migrate status
Prisma->>DB: Check migration status
DB-->>Prisma: Status
Prisma-->>Deploy: Status report
alt Migration status check fails
Deploy->>Notify: Send migration error
Notify-->>Deploy: Notified
Deploy->>Deploy: Exit with error
end
Deploy->>Guard: Execute relation guard script
Guard->>DB: Check guild_role_grants
Guard->>DB: Check guild_automation_manifests
Guard->>DB: Check guild_automation_runs
Guard->>DB: Check guild_automation_drifts
DB-->>Guard: All relations exist
alt Any relation missing
Guard->>Guard: Catch P2021 error
Guard->>Deploy: Exit with ERR_DB_SCHEMA_MISSING
Deploy->>Notify: Send schema error
Notify-->>Deploy: Notified
else All relations verified
Guard-->>Deploy: Success
Deploy->>Services: Restart runtime services
Services-->>Deploy: Restarted
Deploy->>Notify: Send success
Notify-->>Deploy: Notified
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/shared/src/utils/requiredDatabaseRelations.ts`:
- Around line 54-57: Replace the unsafe double-cast on getPrismaClient() in the
verifyRequiredDatabaseRelations default parameter by removing the "as unknown as
RequiredDatabaseStatePrisma" cast and instead define RequiredDatabaseStatePrisma
as a structural type using Pick from the Prisma client (i.e., Pick<PrismaClient,
'modelA' | 'modelB' ...> matching only the models used in this module), then
change the default parameter to call getPrismaClient() directly; update any
import/alias so verifyRequiredDatabaseRelations, RequiredDatabaseStatePrisma,
and getPrismaClient are consistent and type-safe without manual casts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 158cb2b6-a7a0-4a04-9bea-a739b00ac9c5
📒 Files selected for processing (8)
CHANGELOG.mddocs/CI_CD.mdpackages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.tspackages/shared/src/utils/index.tspackages/shared/src/utils/requiredDatabaseRelations.tsscripts/deploy.sh
📜 Review details
🧰 Additional context used
📓 Path-based instructions (28)
**/*.{js,jsx,ts,tsx,vue,html}
📄 CodeRabbit inference engine (.cursor/rules/accessibility-openness.mdc)
Provide accessible UI components using semantic HTML and ARIA attributes where necessary
Files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/dependency-injection.mdc)
**/*.{ts,tsx,js,jsx}: Prefer constructor injection for classes that require dependencies
Avoid global mutable singletons unless necessary
Use explicit interfaces for external dependencies to make testing easier
**/*.{ts,tsx,js,jsx}: Include required references in PRs/code for non-trivial logic: TypeScript (official docs), MDN (JavaScript reference), and official docs for any runtime/framework/libraries used (e.g., Node.js, React) as applicable.
Before assuming behavior of an API, include the doc link and a ≤25-word quote when the change relies on it.
**/*.{ts,tsx,js,jsx}: Prefer named exports for clear usage and easier refactors in TypeScript/JavaScript
Keep import order consistent: external first, then internal modules
Remove dead code and unused imports
**/*.{ts,tsx,js,jsx}: Use PascalCase naming convention for React/UI components
Use camelCase naming convention for variables and functions
Use UPPER_SNAKE_CASE naming convention for constants
Maintain consistent import grouping and ordering within the project, keeping third-party imports separate from local imports
For external data sources (HTTP, database), always validate and sanitize input using type guards or schema validators
**/*.{ts,tsx,js,jsx}: Use Prettier with no semicolons, single quotes, 4-space indent, 80 character width
Files must not exceed 250 lines and this is enforcedImplement TypeScript typecheck and linter in CI quality checks
**/*.{ts,tsx,js,jsx}: Use TypeScript for enhanced type safety
Implement error handling and error logging
Avoid commenting code unless extremely necessary - code should explain itself with descriptive names
Leave NO todos, placeholders or missing pieces in the code
Variables and functions must use camelCase
Constants must use UPPER_SNAKE_CASE
Use arrow functions for methods and computed properties
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements
Maintain consistent import grouping/order: external imports first, then...
Files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/error-handling.mdc)
**/*.{js,jsx,ts,tsx}: Never throw strings. ThrowError(or typed subclasses) with descriptive messages
Include causal error ascausewhen available for better debugging
Define clear, stable error codes (e.g.,ERR_AUTH_EXPIRED,ERR_NETWORK_TIMEOUT)
Provide optional metadata (e.g.,details,retryable,status,correlationId) in error objects
Use domain error classes per area (e.g.,AuthenticationError,ValidationError,NetworkError)
Log errors with structure (message, code, stack, cause, correlationId, user context where appropriate)
MarkretryablevsnonRetryableerrors where helpful for operations
Set timeouts and handle aborts/cancellations; avoid dangling requests in API/network code
Implement backoff for transient failures; avoid infinite retries
Map HTTP status → domain errors; 4xx vs 5xx behave differently (e.g., retry for 5xx/network)
**/*.{js,jsx,ts,tsx}: Use functional components with hooks in React/React Native. Avoid class components.
Keep components focused on a single responsibility; extract complex logic into custom hooks.
Keep state local when possible. Use Context/Zustand/Redux only when necessary for state management.
If props or state traverse more than 3 levels, consider using context or a feature-scoped store instead of prop drilling.
Use performance optimization techniques:React.memo,useMemo,useCallback,Suspense(web), and virtualization for long lists; avoid unnecessary re-renders.
Web accessibility: use semantic HTML, labels, focus management, keyboard navigation, andaria-*attributes as needed.
React Native accessibility: use accessibility props (accessible,accessibilityLabel), proper roles and labels.
Identify and extract repetitive UI components proactively tocomponents/with clear props and minimal coupling.
Web styles: prefer co-located styles or design system tokens; avoid global style leakage.
React Native styles: preferStyleSheet.create, design tokens, and theme providers; avoid in...
Files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)
Introduce interfaces at module boundaries to enable testing and substitutions
**/*.{ts,tsx}: Avoid usinganytype in TypeScript. If unavoidable, useunknownwith type guards and justify with a code comment
Preferinterfacefor defining public object shapes in TypeScript, usetypefor unions and utility types
Use TypeScript utility types such asPartial,Pick,Omit,Readonly, andRecordwhen appropriate
UseI{Name}naming convention for interfaces in TypeScript
UseT{Name}naming convention for type aliases and utility types in TypeScript
**/*.{ts,tsx}: Functions must be less than 50 lines with cyclomatic complexity less than 10
Do not useanytypes - ESLint enforces this at error level
**/*.{ts,tsx}: Prefer types over interfaces for most cases
Don't ever useany- type safety always
Avoid enums; use const objects instead
For complex types, create a separate file to declare them and import them
Avoid usinganytype; if unavoidable, useunknownwith type guards and justify with code comment
Preferinterfacefor public API shapes; usetypefor unions and utility types
Use TypeScript utility types (Partial, Pick, Omit, Readonly, Record)
Files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
packages/backend/src/**/*.ts
📄 CodeRabbit inference engine (CLAUDE.md)
packages/backend/src/**/*.ts: Validation must use Zod schemas inbackend/src/schemas/and be applied viavalidateBody,validateParams, orvalidateQuery
Do not reassignreq.queryin Express middleware - it is read-only in Express 5
Files:
packages/backend/src/startup/verifyRequiredDatabaseState.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/documentation.mdc)
**/*.{js,ts,tsx,jsx}: Minimize comments in code; explain the 'why' when non-obvious, let code express the 'what' through clear naming
Document trade-offs briefly when deviating from ideal patterns
**/*.{js,ts,tsx,jsx}: Store secrets, ports, and hosts in environment variables (.env,.env.example) and never hardcode them
Avoid redundant or decorative AI comments; code should be self-explanatory and only commented when logic is non-obvious; prefer refactoring over lengthy comments
Files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
packages/backend/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/lucky-backend-api.mdc)
packages/backend/src/**/*.{ts,tsx}: Use shared config and env from@lucky/sharedwhen needed; avoid duplicating env parsing in backend code
Keep tokens and secrets in environment variables only; never hardcode or expose in code
Files:
packages/backend/src/startup/verifyRequiredDatabaseState.ts
packages/backend/**
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
The
backendpackage depends onsharedand contains Express API with auth and guild routes
Files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
**/*.{js,mjs,ts,mts}
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
Use Node.js version ≥22 with ESM (ECMAScript modules) only; no CommonJS
Files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
packages/backend/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/subagent-backend.mdc)
packages/backend/**/*.ts: Apply.cursor/rules/lucky-backend-api.mdcfor structure and conventions when acting as backend specialist
Use.cursor/skills/backend-express/SKILL.mdfor Express routes, middleware, and services when acting as backend specialist
Use@lucky/sharedfor config and DB/Redis when needed in backend code
Files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
**/docs/**/*.{md,mdx}
📄 CodeRabbit inference engine (.cursor/rules/documentation.mdc)
**/docs/**/*.{md,mdx}: Keep API documentation in sync with code changes
Document significant architectural design choices
Files:
docs/CI_CD.md
{CHANGELOG.md,docs/**}
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
Update
CHANGELOG.mdand relevantdocs/files when behavior or setup changes
Files:
docs/CI_CD.mdCHANGELOG.md
**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/frontend.mdc)
**/*.{test,spec}.{js,jsx,ts,tsx}: Test behavior, not implementation. Prefer Testing Library utilities for testing React/React Native components.
For React Native tests: mock native modules and test component interactions and accessibility labels.
Files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)
**/*.{test,spec}.{ts,tsx,js,jsx}: Test behavior, not implementation details
Prefer unit tests for core logic; add integration tests at meaningful boundaries
Files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
**/*.{test,spec}.{js,ts,jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/testing-quality.mdc)
**/*.{test,spec}.{js,ts,jsx,tsx}: Use Jest + a React testing library for unit and component tests as applicable
Test behavior, not implementation details
Files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
packages/backend/tests/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/lucky-backend-api.mdc)
Organize tests in
packages/backend/tests/with unit tests underunit/and integration tests underintegration/, following existing patterns with fixtures and setup
Files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
{packages/*/tests/**/*.test.{js,ts},tests/**/*.test.{js,ts}}
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
Add or adjust unit and integration tests when changing behavior; follow existing patterns in
packages/*/testsand roottests/directories
Files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
**/*.{spec,test}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/quality.mdc)
**/*.{spec,test}.{ts,tsx,js,jsx}: Use Jest for unit and integration tests
Test behavior, not implementation details
Run unit, integration tests, and coverage report in CI quality checks
Files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
packages/backend/tests/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/subagent-backend.mdc)
Follow existing patterns for unit and integration tests in
packages/backend/tests/
Files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
{packages/shared/**,prisma/**}/**/*.{ts,js}
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
Use Prisma for PostgreSQL database and Redis for caching with shared client configuration
Files:
packages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.ts
packages/shared/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/lucky-shared.mdc)
packages/shared/**/*.ts: Organize the Lucky Shared Package with the following directory structure: Config inpackages/shared/src/config/(environment, constants, feature toggles, YouTube config); Services inpackages/shared/src/services/(DatabaseService, Redis client/operations, FeatureToggleService, ReactionRoles, RoleManagement); Types inpackages/shared/src/types/(errors, commands, common, discord, music); Utils inpackages/shared/src/utils/(error handling, retry, embeds, log, monitoring, composables, prismaClient)
Do not add dependencies onbotorbackendpackages; shared is the foundational package used by both
Use the single Prisma client located atpackages/shared/src/utils/database/prismaClient.ts; maintain schema in repo root atprisma/schema.prisma; run migrations from root usingnpm run db:migrate
Use Redis client and operations located inpackages/shared/src/services/redis/; use for cache, sessions, and rate limits as defined by existing keys and types
Use typed errors frompackages/shared/src/types/errors/for domain failures; avoid using genericErrorfor application-specific failures
Use shared log and monitoring utils for logging and monitoring in production code paths; do not use directconsolestatements for production logging
Files:
packages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.ts
packages/shared/**/*
📄 CodeRabbit inference engine (.cursor/rules/subagent-data.mdc)
Shared client and services must be located in
packages/shared
Files:
packages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.ts
**/{.scripts,scripts}/**/*.{sh,bash,js,ts}
📄 CodeRabbit inference engine (.cursor/rules/scripts-terminal.mdc)
Use cross-platform deletion utilities instead of OS-specific
rm -rf
Files:
scripts/deploy.sh
{scripts/**,packages/scripts/**}
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
Prefer
packages/scriptsor rootscripts/for one-off automation; avoid maintaining one-time scripts in the repository long term
Files:
scripts/deploy.sh
{**/scripts/**,scripts/**,.github/workflows/**/*.{yml,yaml},**/.gitlab-ci.yml,.circleci/config.yml}
📄 CodeRabbit inference engine (.cursor/rules/workflow.mdc)
{**/scripts/**,scripts/**,.github/workflows/**/*.{yml,yaml},**/.gitlab-ci.yml,.circleci/config.yml}: Use cross-platform environment handling in scripts, cross-platform deletion utilities instead of OS-specific commands, pass non-interactive flags (--yes, --ci) by default in automation, and avoid OS-specific commands
Ensure logs are stream-friendly (no pagers) in scripts; when a pager might be used, pipe to cat
Files:
scripts/deploy.sh
**/index.ts
📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)
Use
index.tsonly to re-export a small, intentional surface per module
Files:
packages/shared/src/utils/index.ts
{CHANGELOG.md,README.md}
📄 CodeRabbit inference engine (.cursor/rules/agent-rules.mdc)
ALWAYS update CHANGELOG.md and README.md as changes are made.
Files:
CHANGELOG.md
CHANGELOG.md
📄 CodeRabbit inference engine (.cursor/rules/templates-examples.mdc)
CHANGELOG.md must be updated with all changes in pull requests
Always update CHANGELOG.md with all code changes
Update CHANGELOG.md with all changes, include breaking changes documentation, and reference issues and PRs
Files:
CHANGELOG.md
🧠 Learnings (19)
📓 Common learnings
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-09T20:22:47.453Z
Learning: For schema, migrations, and database/Redis operations in the shared package, use the `prisma-redis-lucky` skill
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-shared.mdc:0-0
Timestamp: 2026-03-09T20:21:15.595Z
Learning: Applies to packages/shared/**/*.ts : Use the single Prisma client located at `packages/shared/src/utils/database/prismaClient.ts`; maintain schema in repo root at `prisma/schema.prisma`; run migrations from root using `npm run db:migrate`
📚 Learning: 2026-03-09T20:21:15.595Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-shared.mdc:0-0
Timestamp: 2026-03-09T20:21:15.595Z
Learning: Applies to packages/shared/**/*.ts : Use the single Prisma client located at `packages/shared/src/utils/database/prismaClient.ts`; maintain schema in repo root at `prisma/schema.prisma`; run migrations from root using `npm run db:migrate`
Applied to files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/shared/src/utils/requiredDatabaseRelations.tsscripts/deploy.shpackages/shared/src/utils/index.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
📚 Learning: 2026-03-09T20:22:47.453Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-09T20:22:47.453Z
Learning: For schema, migrations, and database/Redis operations in the shared package, use the `prisma-redis-lucky` skill
Applied to files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/backend/tests/unit/startup/requiredDatabaseRelations.test.tsscripts/deploy.shpackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
📚 Learning: 2026-03-09T20:20:47.877Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-discord-bot.mdc:0-0
Timestamp: 2026-03-09T20:20:47.877Z
Learning: Applies to packages/bot/**/*.{ts,tsx} : Use services from `lucky/shared` (DatabaseService, Redis client) for database and cache access; do not instantiate Prisma or Redis directly in the bot package
Applied to files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
📚 Learning: 2026-03-09T20:21:38.098Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-backend.mdc:0-0
Timestamp: 2026-03-09T20:21:38.098Z
Learning: Applies to packages/backend/**/*.ts : Use `lucky/shared` for config and DB/Redis when needed in backend code
Applied to files:
packages/backend/src/startup/verifyRequiredDatabaseState.ts
📚 Learning: 2026-03-09T20:22:47.453Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-09T20:22:47.453Z
Learning: Use database commands: `npm run db:generate` for Prisma generation, `npm run db:migrate` for migrations, `npm run db:deploy` for deployment, `npm run db:studio` for database studio
Applied to files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/shared/src/utils/requiredDatabaseRelations.tsscripts/deploy.sh
📚 Learning: 2026-03-09T20:21:52.065Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-discord.mdc:0-0
Timestamp: 2026-03-09T20:21:52.065Z
Learning: Applies to packages/bot/src/**/*.ts : Use `lucky/shared` for database, Redis, logging, and embed utilities instead of implementing them locally
Applied to files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/shared/src/utils/requiredDatabaseRelations.tspackages/shared/src/utils/index.ts
📚 Learning: 2026-03-09T20:21:08.612Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-project.mdc:0-0
Timestamp: 2026-03-09T20:21:08.612Z
Learning: Applies to {packages/shared/**,prisma/**}/**/*.{ts,js} : Use Prisma for PostgreSQL database and Redis for caching with shared client configuration
Applied to files:
packages/backend/src/startup/verifyRequiredDatabaseState.tspackages/shared/src/utils/requiredDatabaseRelations.ts
📚 Learning: 2026-03-09T20:21:46.291Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-data.mdc:0-0
Timestamp: 2026-03-09T20:21:46.291Z
Learning: Use `npm run db:deploy` command from repo root for deploying migrations
Applied to files:
docs/CI_CD.mdscripts/deploy.sh
📚 Learning: 2026-03-09T20:21:38.098Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-backend.mdc:0-0
Timestamp: 2026-03-09T20:21:38.098Z
Learning: Applies to packages/backend/tests/**/*.ts : Follow existing patterns for unit and integration tests in `packages/backend/tests/`
Applied to files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
📚 Learning: 2026-03-09T20:20:38.694Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-backend-api.mdc:0-0
Timestamp: 2026-03-09T20:20:38.694Z
Learning: Applies to packages/backend/tests/**/*.{ts,tsx} : Organize tests in `packages/backend/tests/` with unit tests under `unit/` and integration tests under `integration/`, following existing patterns with fixtures and setup
Applied to files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
📚 Learning: 2026-03-09T20:21:08.612Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-project.mdc:0-0
Timestamp: 2026-03-09T20:21:08.612Z
Learning: Applies to {packages/*/tests/**/*.test.{js,ts},tests/**/*.test.{js,ts}} : Add or adjust unit and integration tests when changing behavior; follow existing patterns in `packages/*/tests` and root `tests/` directories
Applied to files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
📚 Learning: 2026-03-09T20:21:31.459Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/quality.mdc:0-0
Timestamp: 2026-03-09T20:21:31.459Z
Learning: Applies to tests/**/*.test.{ts,tsx,js,jsx} : Add integration tests where appropriate
Applied to files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
📚 Learning: 2026-03-09T20:22:47.453Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-09T20:22:47.453Z
Learning: For unit tests and Jest ESM mocks, use the `testing-lucky` skill
Applied to files:
packages/backend/tests/unit/startup/requiredDatabaseRelations.test.tspackages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts
📚 Learning: 2026-03-09T20:21:46.291Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-data.mdc:0-0
Timestamp: 2026-03-09T20:21:46.291Z
Learning: Applies to prisma/migrations/**/* : Database migrations must be located in `prisma/migrations/`
Applied to files:
packages/shared/src/utils/requiredDatabaseRelations.ts
📚 Learning: 2026-03-09T20:21:46.291Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-data.mdc:0-0
Timestamp: 2026-03-09T20:21:46.291Z
Learning: Applies to prisma/schema.prisma : Schema definitions must be located in `prisma/schema.prisma`
Applied to files:
packages/shared/src/utils/requiredDatabaseRelations.ts
📚 Learning: 2026-03-09T20:21:46.291Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-data.mdc:0-0
Timestamp: 2026-03-09T20:21:46.291Z
Learning: Use `npm run db:generate` command from repo root for Prisma code generation
Applied to files:
scripts/deploy.sh
📚 Learning: 2026-03-09T20:21:15.595Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-shared.mdc:0-0
Timestamp: 2026-03-09T20:21:15.595Z
Learning: Applies to packages/shared/**/*.ts : Do not add dependencies on `bot` or `backend` packages; shared is the foundational package used by both
Applied to files:
packages/shared/src/utils/index.ts
📚 Learning: 2026-03-09T20:22:09.954Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/typescript.mdc:0-0
Timestamp: 2026-03-09T20:22:09.954Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use named exports for clear usage and easier refactors
Applied to files:
packages/shared/src/utils/index.ts
🪛 GitHub Actions: CI/CD Pipeline
packages/shared/src/utils/requiredDatabaseRelations.ts
[error] 56-56: TS2352: Conversion of type 'PrismaClient' to type 'RequiredDatabaseStatePrisma' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
🪛 GitHub Actions: SonarCloud Analysis
packages/shared/src/utils/requiredDatabaseRelations.ts
[error] 56-56: Type conversion error: Conversion of type 'PrismaClient' to type 'RequiredDatabaseStatePrisma' may be a mistake. If intentional, convert the expression to 'unknown' first. [tsc] (TS2352) during build:shared step (tsc -b --force).
🔇 Additional comments (8)
packages/shared/src/utils/requiredDatabaseRelations.ts (1)
35-52: Good centralization of required-relation checks.This relation-check table is clear and makes backend/deploy guard behavior consistent.
packages/shared/src/utils/index.ts (1)
9-9: Public re-export looks correct.Exposing the shared relation guard here keeps consumption consistent from
@lucky/shared/utils.docs/CI_CD.md (1)
75-85: Deploy preflight docs are clear and aligned with behavior.The added migration-status + relation-guard narrative is explicit and operationally useful.
packages/backend/src/startup/verifyRequiredDatabaseState.ts (1)
1-4: Nice simplification via shared guard delegation.This keeps startup DB verification behavior centralized in one implementation.
CHANGELOG.md (1)
165-169: Changelog entry is accurate and scoped to the rollout guard changes.scripts/deploy.sh (1)
253-280: Pre-rollout DB gate hardening is solid.Running
migrate statusand the shared relation guard before restart is the right fail-fast sequence.packages/backend/tests/unit/startup/requiredDatabaseRelations.test.ts (1)
38-130: Great coverage for the shared relation verifier contract.Healthy path, per-table missing relation mapping, and unknown-error passthrough are all covered.
packages/backend/tests/unit/startup/verifyRequiredDatabaseState.test.ts (1)
21-47: Delegation-focused tests look correct.These assertions capture the new contract: one shared guard call and unchanged error propagation.
|
Addressed in commit 238ca88: removed unsafe cast, switched to generated Prisma Pick typing, and revalidated with type-check + tests.
|
* fix(deploy): fail fast on db drift before rollout * fix(shared): satisfy prisma guard typing in ci build * fix(shared): remove unsafe prisma cast in db guard



Summary
guild_role_grantsprisma migrate statusbefore service restartVerification
npm run test --workspace=packages/backend -- tests/unit/startup/requiredDatabaseRelations.test.ts tests/unit/startup/verifyRequiredDatabaseState.test.ts tests/unit/bootstrap.test.tsbash -n scripts/deploy.shNotes
npm run type:check --workspace=packages/sharedandnpm run type:check --workspace=packages/backendstill hit existing baseline failures in this repo (generated Prisma + pre-existing strict typing issues outside this change scope).Summary by CodeRabbit