mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
- Created TODO files for Testing, DBAL, Frontend, Packages, Database, and Lua Scripting. - Updated README with a quick reference table for all TODO files and their priorities. - Added specific tasks for improving testing coverage, implementing DBAL features, enhancing frontend components, and refining package management. - Included documentation tasks to ensure thorough coverage and clarity across all areas. - Implemented initial unit tests for the useAuth hook and improved password generation logic. - Enhanced package loader functionality to support modular package seed data retrieval. - Updated page renderer to include public role in permission checks. - Added comments for future unit tests in workflow engine and other critical areas.
3.1 KiB
3.1 KiB
Prisma Database Setup
The MetaBuilder project now uses Prisma as its database layer, replacing the previous spark.kv key-value store.
Quick Start
1. Install Dependencies
npm install
2. Set up Environment Variables
Create a .env file in the root directory:
DATABASE_URL="file:./dev.db"
3. Generate Prisma Client
npm run db:generate
4. Create/Update Database
npm run db:push
5. Start Development Server
npm run dev
Database Schema
The Prisma schema is defined in prisma/schema.prisma and includes:
- Users: User accounts, credentials, and authentication
- Content: Workflows, Lua scripts, pages, and data schemas
- Components: UI component hierarchy and configurations
- Packages: Installed packages and their data
- Tenancy: Multi-tenant support and power transfers
- Configuration: SMTP, CSS classes, dropdown configs, and system settings
npm Scripts
npm run db:generate- Generate Prisma Client from schemanpm run db:push- Push schema changes to database (dev)npm run db:migrate- Run migrations (production)
Database Files
prisma/schema.prisma- Database schema definitionprisma/migrations/- Migration historydev.db- SQLite database file (gitignored)src/lib/prisma.ts- Prisma client singletonsrc/lib/database.ts- Database access layer
Switching Database Providers
PostgreSQL (Recommended for Production)
- Update
prisma/schema.prisma:
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
- Update
.env:
DATABASE_URL="postgresql://user:password@localhost:5432/metabuilder"
- Run:
npm run db:push
MySQL
- Update
prisma/schema.prisma:
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
- Update
.env:
DATABASE_URL="mysql://user:password@localhost:3306/metabuilder"
- Run:
npm run db:push
Data Migration
If you have existing data from the old spark.kv system:
- Export data (before migration):
const jsonData = await Database.exportDatabase()
// Save to file
- After Prisma setup, import:
await Database.importDatabase(jsonData)
Troubleshooting
Error: Cannot find module '@prisma/client'
Run: npm run db:generate
Error: Database file doesn't exist
Run: npm run db:push
Error: Database locked (SQLite)
Kill any processes using the database or restart your computer.
Migration conflicts
Delete prisma/migrations/ and dev.db, then run npm run db:push
Production Deployment
- Use PostgreSQL or MySQL (not SQLite)
- Set
DATABASE_URLenvironment variable - Run migrations:
npm run db:migrate - Deploy application
Additional Resources
- Prisma Documentation
- Prisma Schema Reference TODO: The migration guide link should be relative to docs/database (remove ./docs/).
- Migration Guide