skills/vendix-prisma-seed/SKILL.md
Vendix database seed patterns: current seed runner, production seed, flat seed modules, Prisma 7 shared client, idempotency, destructive dev cleanup, and the `syncRolePermissions` helper for canonical role-permission synchronization. Trigger: When creating seeds, editing seed modules, running seed scripts, or resetting development data.
npx skillsauth add rzyfront/vendix vendix-prisma-seedInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
apps/backend/prisma/seed.ts.apps/backend/prisma/seed-production.ts.apps/backend/prisma/seeds/*.seed.ts.apps/backend/prisma/seeds/shared/client.ts.apps/backend/prisma/seeds/shared/database.ts and database-scripts/clean.ts.Seeds are flat modules under apps/backend/prisma/seeds/, not seeds/dev and seeds/prod directories.
seed.ts runs modules sequentially, logs errors per module, continues, and exits with code 1 if any module failed.
Current main order includes default templates, permissions/roles, system payment methods, organizations/stores, legal documents, users, products/categories, PUC/account mappings, domains, addresses, inventory locations, test orders, help articles, payroll defaults, AI apps, and subscription plans.
seed-production.ts is a lighter runner for essential production data: templates, permissions/roles, account mappings, payroll rules, AI apps, system payment methods, and default trial subscription plan.
Commented usage is npx tsx prisma/seed-production.ts; there is no current backend package script pointing to it.
npm run db:seed -w apps/backend
npm run db:reset -w apps/backend
npm run db:clean -w apps/backend
npm run db:reset-seed
Do not run reset/clean unless explicitly requested; these are destructive.
seeds/shared/client.ts uses a singleton Prisma 7 client with PrismaPg adapter and pg.Pool. It falls back to a local placeholder URL if DATABASE_URL is missing.
upsert for stable records.findUnique + update/create when composite/business logic needs custom behavior.ON CONFLICT DO NOTHING in migration seed SQL.Examples in current code:
organization_id_code.code to preserve ids.clearDatabase() uses deleteMany({}) in reverse dependency order. It is destructive and intended for local/dev seed utilities only. Do not use it in production flows.
syncRolePermissionsLocation: apps/backend/prisma/seeds/shared/sync-role-permissions.ts.
Canonical helper for synchronizing a role's role_permissions rows against a desired permission set. Replaces the legacy "upsert in a loop + optional deleteMany({ permission_id: { notIn } })" pattern that previously lived inline in permissions-roles.seed.ts.
import { syncRolePermissions } from './shared/sync-role-permissions';
await syncRolePermissions(
client, // PrismaClient | Prisma.TransactionClient
roleId, // number — roles.id
allowedPermissionIds, // number[] — canonical permissions.id list
label, // string — log label, e.g. "STORE_ADMIN (manager)"
);
// → { added: number; revoked: number }
permissions.findMany().allowedPermissionIds as authoritative for that role.createMany({ skipDuplicates: true }) against the
@@unique([role_id, permission_id]) constraint — re-runs never duplicate
rows.deleteMany({ permission_id: { notIn: allowedIds } }),
which is a set-difference operation. The second run sees an empty diff and
is a no-op.allowedIds is handled safely: the helper deletes everything for
that role and skips the insert pass — useful when fully retiring a role's
permissions.permissions-roles.seed.ts)const managerPermissions = allPermissions.filter(/* canonical filter */);
const managerSync = await syncRolePermissions(
client,
managerRole.id,
managerPermissions.map((p) => p.id),
'STORE_ADMIN (manager)',
);
assignmentsCreated += managerSync.added;
// Logs: "🔄 Synced STORE_ADMIN (manager): +N added, -M revoked (canonical=K)"
The helper replaced ~15 lines per role of upsert loops plus the
deleteMany+notIn revocation block, while preserving the existing
assignmentsCreated accounting and console.log traceability. All seven
system roles (super_admin, owner, admin, manager, supervisor,
employee, customer, cashier) now use it.
vendix-prisma-migrationsvendix-prisma-schemavendix-prisma-scopesdevelopment
Mobile app development rules for Vendix Expo/React Native project. Trigger: When editing, creating, or modifying any file under apps/mobile, or when developing mobile-specific features.
development
Feature gating by store subscription state: global store write guard, AI feature gate, Redis feature resolution, quota consumption, frontend paywall interceptor, banner, and subscription UI states. Trigger: When adding feature gates, paywalls, subscription-based access control, protecting store write operations, AI feature gates, or rollout flags.
testing
SaaS subscription billing for Vendix stores: plan pricing, invoices, Wompi platform payments, manual payments, partner commissions, payouts, proration, and dunning. Trigger: When creating SaaS invoices, working with partner rev-share, margin/surcharge pricing, invoice sequence allocation, partner payout batches, subscription payments, manual payments, or dunning flows.
development
Periodic quota counters with Redis, UTC period keys, Lua-based idempotent AI quota consumption, request-id deduplication, and post-success consumption. Trigger: When building quota counters, enforcing monthly/daily feature caps, or reusing AI quota patterns for uploads, emails, exports, or rate-limited features.