ShipNowKit uses Prisma ORM as the database access layer, providing type-safe database operations and powerful migration management capabilities.
You can find schema definitions and configuration files in the db/prisma directory.
Configure Database Provider
ShipNowKit uses SQLite as the default development database, but you can switch between multiple database types.
Switch Database Type
ShipNowKit provides convenient script commands to switch database types:
# SQLite (recommended for local development)
npm run db:use:sqlite
# PostgreSQL
npm run db:use:postgresql
# MySQL
npm run db:use:mysql
# MongoDB
npm run db:use:mongodbThese scripts automatically update the provider configuration in the db/prisma/schema.prisma file.
Configure Database Connection
After switching database types, you need to configure the corresponding DATABASE_URL in the .env.local file:
# SQLite example
DATABASE_URL="file:./db/prisma/dev.db"
# PostgreSQL example
DATABASE_URL="postgresql://user:password@localhost:5432/shipnowkit"
# MySQL example
DATABASE_URL="mysql://user:password@localhost:3306/shipnowkit"
# MongoDB example
DATABASE_URL="mongodb://localhost:27017/shipnowkit"Database Models
ShipNowKit's database models are defined in the db/prisma/schema.prisma file, including the following main models:
- User - User model, stores basic user information
- Account - Account model, stores OAuth account information
- Session - Session model, stores user session information
- Verification - Verification model, stores email verification and other information
- Customer - Customer model, linked to payment providers
- Subscription - Subscription model, manages user subscription status
- OneTimePayment - One-time payment model
- Price - Price model, stores product pricing information
- SubscriptionTransaction - Subscription transaction model, records subscription transaction history
- SystemConfig - System configuration model, stores configurable items
- ConfigAuditLog - Configuration audit log, records configuration change history
Database Service Layer
ShipNowKit recommends encapsulating all database operations in service files under the db/services/ directory, rather than using Prisma Client directly in components or API routes.
Benefits of this organization:
- Code Reusability: Same query logic can be reused in multiple places
- Easy Testing: Database operation logic can be tested independently
- Type Safety: TypeScript type checking ensures data consistency
- Error Handling: Unified error handling mechanism
For example, all user-related database operations are in the db/services/user.ts file:
import { prisma } from "../client";
export async function findUserByEmail(email: string) {
return await prisma.user.findUnique({
where: { email }
});
}Update the codebase
Learn how to update your ShipNowKit codebase from the upstream repository to get the latest updates and features. Step-by-step guide for syncing with upstream changes.
Using Database Client
Learn how to use Prisma Client for database operations in ShipNowKit. Understand basic operations for querying, creating, updating, and deleting records.