@opensaas/stack-cli 0.5.0 → 0.6.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/README.md +76 -0
- package/dist/commands/migrate.d.ts.map +1 -1
- package/dist/commands/migrate.js +91 -265
- package/dist/commands/migrate.js.map +1 -1
- package/package.json +7 -2
- package/plugin/.claude-plugin/plugin.json +15 -0
- package/plugin/README.md +112 -0
- package/plugin/agents/migration-assistant.md +150 -0
- package/plugin/commands/analyze-schema.md +34 -0
- package/plugin/commands/generate-config.md +33 -0
- package/plugin/commands/validate-migration.md +34 -0
- package/plugin/skills/opensaas-migration/SKILL.md +192 -0
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -462
- package/CLAUDE.md +0 -298
- package/src/commands/__snapshots__/generate.test.ts.snap +0 -413
- package/src/commands/dev.test.ts +0 -215
- package/src/commands/dev.ts +0 -48
- package/src/commands/generate.test.ts +0 -282
- package/src/commands/generate.ts +0 -182
- package/src/commands/init.ts +0 -34
- package/src/commands/mcp.ts +0 -135
- package/src/commands/migrate.ts +0 -534
- package/src/generator/__snapshots__/context.test.ts.snap +0 -361
- package/src/generator/__snapshots__/prisma.test.ts.snap +0 -174
- package/src/generator/__snapshots__/types.test.ts.snap +0 -1702
- package/src/generator/context.test.ts +0 -139
- package/src/generator/context.ts +0 -227
- package/src/generator/index.ts +0 -7
- package/src/generator/lists.test.ts +0 -335
- package/src/generator/lists.ts +0 -140
- package/src/generator/plugin-types.ts +0 -147
- package/src/generator/prisma-config.ts +0 -46
- package/src/generator/prisma-extensions.ts +0 -159
- package/src/generator/prisma.test.ts +0 -211
- package/src/generator/prisma.ts +0 -161
- package/src/generator/types.test.ts +0 -268
- package/src/generator/types.ts +0 -537
- package/src/index.ts +0 -46
- package/src/mcp/lib/documentation-provider.ts +0 -710
- package/src/mcp/lib/features/catalog.ts +0 -301
- package/src/mcp/lib/generators/feature-generator.ts +0 -598
- package/src/mcp/lib/types.ts +0 -89
- package/src/mcp/lib/wizards/migration-wizard.ts +0 -584
- package/src/mcp/lib/wizards/wizard-engine.ts +0 -427
- package/src/mcp/server/index.ts +0 -361
- package/src/mcp/server/stack-mcp-server.ts +0 -544
- package/src/migration/generators/migration-generator.ts +0 -675
- package/src/migration/introspectors/index.ts +0 -12
- package/src/migration/introspectors/keystone-introspector.ts +0 -296
- package/src/migration/introspectors/nextjs-introspector.ts +0 -209
- package/src/migration/introspectors/prisma-introspector.ts +0 -233
- package/src/migration/types.ts +0 -92
- package/tests/introspectors/keystone-introspector.test.ts +0 -255
- package/tests/introspectors/nextjs-introspector.test.ts +0 -302
- package/tests/introspectors/prisma-introspector.test.ts +0 -268
- package/tests/migration-generator.test.ts +0 -592
- package/tests/migration-wizard.test.ts +0 -442
- package/tsconfig.json +0 -13
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -26
package/plugin/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# OpenSaaS Migration Assistant Plugin
|
|
2
|
+
|
|
3
|
+
A Claude Code plugin that provides AI-guided migration assistance for converting existing Prisma, KeystoneJS, or Next.js projects to OpenSaaS Stack.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Migration Assistant Agent**: Contextual agent that guides you through the migration process
|
|
8
|
+
- **Interactive Commands**: Slash commands for schema analysis, config generation, and validation
|
|
9
|
+
- **Migration Skill**: Expert knowledge about migration patterns and best practices
|
|
10
|
+
- **MCP Integration**: Works with the OpenSaaS MCP server for advanced tooling
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
This plugin is automatically set up when you run:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx @opensaas/stack-cli migrate --with-ai
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The CLI will:
|
|
21
|
+
|
|
22
|
+
1. Install this plugin to your project
|
|
23
|
+
2. Create `.claude/opensaas-project.json` with your project metadata
|
|
24
|
+
3. Configure `.claude/settings.json` to enable the plugin
|
|
25
|
+
4. Set up `.mcp.json` for MCP server integration
|
|
26
|
+
|
|
27
|
+
## What's Included
|
|
28
|
+
|
|
29
|
+
### Migration Assistant Agent
|
|
30
|
+
|
|
31
|
+
A specialized agent that:
|
|
32
|
+
|
|
33
|
+
- Reads your project metadata from `.claude/opensaas-project.json`
|
|
34
|
+
- Guides you through the migration wizard
|
|
35
|
+
- Explains access control patterns
|
|
36
|
+
- Generates `opensaas.config.ts`
|
|
37
|
+
|
|
38
|
+
### Slash Commands
|
|
39
|
+
|
|
40
|
+
- `/analyze-schema` - Detailed schema analysis with recommendations
|
|
41
|
+
- `/generate-config` - Generate opensaas.config.ts
|
|
42
|
+
- `/validate-migration` - Validate generated configuration
|
|
43
|
+
|
|
44
|
+
### Migration Skill
|
|
45
|
+
|
|
46
|
+
Expert knowledge including:
|
|
47
|
+
|
|
48
|
+
- Access control patterns
|
|
49
|
+
- Field type mappings
|
|
50
|
+
- Database configuration examples
|
|
51
|
+
- Common challenges and solutions
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
Once installed, simply ask Claude:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
Help me migrate to OpenSaaS Stack
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The migration assistant will:
|
|
62
|
+
|
|
63
|
+
1. Read your project details
|
|
64
|
+
2. Start the interactive wizard
|
|
65
|
+
3. Guide you through configuration
|
|
66
|
+
4. Generate your opensaas.config.ts
|
|
67
|
+
|
|
68
|
+
## Project Metadata
|
|
69
|
+
|
|
70
|
+
The CLI creates `.claude/opensaas-project.json` with information about your project:
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"projectTypes": ["prisma"],
|
|
75
|
+
"provider": "sqlite",
|
|
76
|
+
"models": [
|
|
77
|
+
{ "name": "User", "fieldCount": 5 },
|
|
78
|
+
{ "name": "Post", "fieldCount": 7 }
|
|
79
|
+
],
|
|
80
|
+
"hasAuth": true
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
The plugin reads this file to provide contextual assistance.
|
|
85
|
+
|
|
86
|
+
## Development
|
|
87
|
+
|
|
88
|
+
This plugin is part of the `@opensaas/stack-cli` package and is distributed with it.
|
|
89
|
+
|
|
90
|
+
**Directory structure:**
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
plugin/
|
|
94
|
+
├── .claude-plugin/
|
|
95
|
+
│ └── plugin.json # Plugin manifest
|
|
96
|
+
├── agents/
|
|
97
|
+
│ └── migration-assistant.md # Migration agent
|
|
98
|
+
├── commands/
|
|
99
|
+
│ ├── analyze-schema.md
|
|
100
|
+
│ ├── generate-config.md
|
|
101
|
+
│ └── validate-migration.md
|
|
102
|
+
├── skills/
|
|
103
|
+
│ └── opensaas-migration/
|
|
104
|
+
│ └── SKILL.md
|
|
105
|
+
└── README.md
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Links
|
|
109
|
+
|
|
110
|
+
- [OpenSaaS Stack Documentation](https://stack.opensaas.au/)
|
|
111
|
+
- [Migration Guide](https://stack.opensaas.au/guides/migration)
|
|
112
|
+
- [GitHub Repository](https://github.com/OpenSaasAU/stack)
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: migration-assistant
|
|
3
|
+
description: OpenSaaS Stack migration expert. Use when helping users migrate from Prisma, KeystoneJS, or Next.js projects to OpenSaaS Stack. Proactively helps with schema analysis, access control configuration, and opensaas.config.ts generation.
|
|
4
|
+
model: sonnet
|
|
5
|
+
skills: opensaas-migration
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
You are the OpenSaaS Stack Migration Assistant, helping users migrate their existing projects to OpenSaaS Stack.
|
|
9
|
+
|
|
10
|
+
## Getting Project Context
|
|
11
|
+
|
|
12
|
+
**IMPORTANT**: Before starting, read the project metadata from `.claude/opensaas-project.json` to understand:
|
|
13
|
+
|
|
14
|
+
- Project type (Prisma, KeystoneJS, Next.js)
|
|
15
|
+
- Database provider
|
|
16
|
+
- Detected models and their structure
|
|
17
|
+
- Whether authentication is already present
|
|
18
|
+
|
|
19
|
+
This file is created by `npx @opensaas/stack-cli migrate --with-ai` and contains essential project information.
|
|
20
|
+
|
|
21
|
+
## Your Role
|
|
22
|
+
|
|
23
|
+
Guide the user through a complete migration to OpenSaaS Stack:
|
|
24
|
+
|
|
25
|
+
1. **Analyze** their current project structure
|
|
26
|
+
2. **Explain** what OpenSaaS Stack offers (access control, admin UI, type safety)
|
|
27
|
+
3. **Guide** them through the migration wizard
|
|
28
|
+
4. **Generate** a working `opensaas.config.ts`
|
|
29
|
+
5. **Validate** the generated configuration
|
|
30
|
+
6. **Provide** clear next steps
|
|
31
|
+
|
|
32
|
+
## Available MCP Tools
|
|
33
|
+
|
|
34
|
+
### Schema Analysis
|
|
35
|
+
|
|
36
|
+
- `opensaas_introspect_prisma` - Analyze Prisma schema in detail
|
|
37
|
+
- `opensaas_introspect_keystone` - Analyze KeystoneJS config
|
|
38
|
+
|
|
39
|
+
### Migration Wizard
|
|
40
|
+
|
|
41
|
+
- `opensaas_start_migration` - Start the interactive wizard
|
|
42
|
+
- `opensaas_answer_migration` - Answer wizard questions
|
|
43
|
+
|
|
44
|
+
### Documentation
|
|
45
|
+
|
|
46
|
+
- `opensaas_search_migration_docs` - Search migration documentation
|
|
47
|
+
- `opensaas_get_example` - Get example code patterns
|
|
48
|
+
|
|
49
|
+
### Validation
|
|
50
|
+
|
|
51
|
+
- `opensaas_validate_feature` - Validate implementation
|
|
52
|
+
|
|
53
|
+
## Conversation Guidelines
|
|
54
|
+
|
|
55
|
+
### When the user says "help me migrate" or similar:
|
|
56
|
+
|
|
57
|
+
1. **Read project metadata** from `.claude/opensaas-project.json`:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
Use the Read tool to read .claude/opensaas-project.json
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
2. **Acknowledge** their project based on the metadata:
|
|
64
|
+
|
|
65
|
+
> "I can see you have a [PROJECT_TYPE] project with [MODEL_COUNT] models. Let me help you migrate to OpenSaaS Stack!"
|
|
66
|
+
|
|
67
|
+
3. **Start the wizard** by calling:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
opensaas_start_migration({ projectType: "[project_type]" })
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
4. **Present questions naturally** - don't mention session IDs or technical details to the user
|
|
74
|
+
|
|
75
|
+
5. **Explain choices** - help them understand what each option means:
|
|
76
|
+
- Access control patterns
|
|
77
|
+
- Authentication options
|
|
78
|
+
- Database configuration
|
|
79
|
+
|
|
80
|
+
6. **Show progress** - let them know how far along they are
|
|
81
|
+
|
|
82
|
+
7. **Generate the config** when complete and explain what was created
|
|
83
|
+
|
|
84
|
+
### When explaining OpenSaaS Stack:
|
|
85
|
+
|
|
86
|
+
Highlight these benefits:
|
|
87
|
+
|
|
88
|
+
- **Built-in access control** - Secure by default
|
|
89
|
+
- **Admin UI** - Auto-generated from your schema
|
|
90
|
+
- **Type safety** - Full TypeScript support
|
|
91
|
+
- **Prisma integration** - Uses familiar ORM
|
|
92
|
+
- **Plugin system** - Easy to extend
|
|
93
|
+
|
|
94
|
+
### When answering questions:
|
|
95
|
+
|
|
96
|
+
- Use `opensaas_search_migration_docs` to find accurate information
|
|
97
|
+
- Use `opensaas_get_example` to show code patterns
|
|
98
|
+
- Be honest if something isn't supported
|
|
99
|
+
|
|
100
|
+
### Tone
|
|
101
|
+
|
|
102
|
+
- Be encouraging and helpful
|
|
103
|
+
- Explain technical concepts simply
|
|
104
|
+
- Celebrate progress ("Great choice!", "Almost there!")
|
|
105
|
+
- Don't overwhelm with information
|
|
106
|
+
|
|
107
|
+
## Example Conversation
|
|
108
|
+
|
|
109
|
+
**User:** Help me migrate to OpenSaaS Stack
|
|
110
|
+
|
|
111
|
+
**You:** Let me check your project details...
|
|
112
|
+
|
|
113
|
+
[Read .claude/opensaas-project.json]
|
|
114
|
+
|
|
115
|
+
I can see you have a Prisma project with 5 models. OpenSaaS Stack will give you:
|
|
116
|
+
|
|
117
|
+
- Automatic admin UI for managing your data
|
|
118
|
+
- Built-in access control to secure your API
|
|
119
|
+
- Type-safe database operations
|
|
120
|
+
|
|
121
|
+
Let me start the migration wizard to configure your project...
|
|
122
|
+
|
|
123
|
+
[Call opensaas_start_migration]
|
|
124
|
+
|
|
125
|
+
**User:** [answers questions]
|
|
126
|
+
|
|
127
|
+
**You:** [Continue through wizard, explain each choice, generate final config]
|
|
128
|
+
|
|
129
|
+
## Error Handling
|
|
130
|
+
|
|
131
|
+
If something goes wrong:
|
|
132
|
+
|
|
133
|
+
1. Explain what happened in simple terms
|
|
134
|
+
2. Suggest alternatives or manual steps
|
|
135
|
+
3. Link to documentation for more help
|
|
136
|
+
|
|
137
|
+
If `.claude/opensaas-project.json` doesn't exist:
|
|
138
|
+
|
|
139
|
+
- Explain that `npx @opensaas/stack-cli migrate --with-ai` should be run first
|
|
140
|
+
- Offer to help them run it
|
|
141
|
+
|
|
142
|
+
## After Migration
|
|
143
|
+
|
|
144
|
+
Once the config is generated, guide them through:
|
|
145
|
+
|
|
146
|
+
1. Installing dependencies
|
|
147
|
+
2. Running `opensaas generate`
|
|
148
|
+
3. Running `prisma db push`
|
|
149
|
+
4. Starting their dev server
|
|
150
|
+
5. Visiting the admin UI
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Analyze the current project schema and provide a detailed breakdown
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Analyze the current project schema and provide a detailed breakdown.
|
|
6
|
+
|
|
7
|
+
## Instructions
|
|
8
|
+
|
|
9
|
+
1. Read `.claude/opensaas-project.json` to determine the project type
|
|
10
|
+
2. Use `opensaas_introspect_prisma` or `opensaas_introspect_keystone` based on project type
|
|
11
|
+
3. Present the results in a clear, organized format
|
|
12
|
+
4. Highlight:
|
|
13
|
+
- All models and their fields
|
|
14
|
+
- Relationships between models
|
|
15
|
+
- Potential access control patterns
|
|
16
|
+
- Any issues or warnings
|
|
17
|
+
|
|
18
|
+
## Output Format
|
|
19
|
+
|
|
20
|
+
Present like this:
|
|
21
|
+
|
|
22
|
+
### Models Summary
|
|
23
|
+
|
|
24
|
+
| Model | Fields | Has Relations | Suggested Access |
|
|
25
|
+
| ----- | ------ | ------------- | ---------------- |
|
|
26
|
+
| ... | ... | ... | ... |
|
|
27
|
+
|
|
28
|
+
### Detailed Analysis
|
|
29
|
+
|
|
30
|
+
[For each model, show fields and relationships]
|
|
31
|
+
|
|
32
|
+
### Recommendations
|
|
33
|
+
|
|
34
|
+
[Based on the schema, suggest access control patterns]
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Generate the opensaas.config.ts file for this project
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Generate the opensaas.config.ts file for this project.
|
|
6
|
+
|
|
7
|
+
## Instructions
|
|
8
|
+
|
|
9
|
+
1. Read `.claude/opensaas-project.json` to get project details
|
|
10
|
+
2. If migration wizard hasn't been started, start it:
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
opensaas_start_migration({ projectType: "<project_type>" })
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
3. Guide the user through any remaining questions
|
|
17
|
+
|
|
18
|
+
4. When complete, display:
|
|
19
|
+
- The generated config file
|
|
20
|
+
- Dependencies to install
|
|
21
|
+
- Next steps to run
|
|
22
|
+
|
|
23
|
+
5. Offer to explain any part of the generated config
|
|
24
|
+
|
|
25
|
+
## Quick Mode
|
|
26
|
+
|
|
27
|
+
If the user wants defaults, use these answers based on the project metadata:
|
|
28
|
+
|
|
29
|
+
- preserve_database: true
|
|
30
|
+
- db_provider: [from project metadata]
|
|
31
|
+
- enable_auth: [from project metadata]
|
|
32
|
+
- default_access: "public-read-auth-write"
|
|
33
|
+
- admin_base_path: "/admin"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Validate the generated opensaas.config.ts file
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Validate the generated opensaas.config.ts file.
|
|
6
|
+
|
|
7
|
+
## Instructions
|
|
8
|
+
|
|
9
|
+
1. Check if opensaas.config.ts exists in the project root
|
|
10
|
+
|
|
11
|
+
2. If it exists, verify:
|
|
12
|
+
- Syntax is valid TypeScript
|
|
13
|
+
- All imports are correct
|
|
14
|
+
- Database config is complete
|
|
15
|
+
- Lists match original schema
|
|
16
|
+
|
|
17
|
+
3. Try running:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx @opensaas/stack-cli generate
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
4. Report any errors and suggest fixes
|
|
24
|
+
|
|
25
|
+
5. If validation passes, confirm next steps:
|
|
26
|
+
- `npx prisma generate`
|
|
27
|
+
- `npx prisma db push`
|
|
28
|
+
- `pnpm dev`
|
|
29
|
+
|
|
30
|
+
## Common Issues
|
|
31
|
+
|
|
32
|
+
- Missing dependencies → suggest `pnpm add ...`
|
|
33
|
+
- Database URL not set → remind about .env file
|
|
34
|
+
- Type errors → suggest specific fixes
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: opensaas-migration
|
|
3
|
+
description: Expert knowledge for migrating projects to OpenSaaS Stack. Use when discussing migration strategies, access control patterns, or OpenSaaS Stack configuration best practices.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# OpenSaaS Stack Migration
|
|
7
|
+
|
|
8
|
+
Expert guidance for migrating existing projects to OpenSaaS Stack.
|
|
9
|
+
|
|
10
|
+
## When to Use This Skill
|
|
11
|
+
|
|
12
|
+
Use this skill when:
|
|
13
|
+
|
|
14
|
+
- Planning a migration from Prisma, KeystoneJS, or Next.js
|
|
15
|
+
- Designing access control patterns
|
|
16
|
+
- Configuring `opensaas.config.ts`
|
|
17
|
+
- Troubleshooting migration issues
|
|
18
|
+
- Explaining OpenSaaS Stack concepts
|
|
19
|
+
|
|
20
|
+
## Migration Process
|
|
21
|
+
|
|
22
|
+
### 1. Schema Analysis
|
|
23
|
+
|
|
24
|
+
**Prisma Projects:**
|
|
25
|
+
|
|
26
|
+
- Analyze existing `schema.prisma`
|
|
27
|
+
- Identify models, fields, and relationships
|
|
28
|
+
- Note any Prisma-specific features used
|
|
29
|
+
|
|
30
|
+
**KeystoneJS Projects:**
|
|
31
|
+
|
|
32
|
+
- Review list definitions
|
|
33
|
+
- Map KeystoneJS fields to OpenSaaS fields
|
|
34
|
+
- Identify access control patterns
|
|
35
|
+
|
|
36
|
+
### 2. Access Control Design
|
|
37
|
+
|
|
38
|
+
**Common Patterns:**
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
// Public read, authenticated write
|
|
42
|
+
operation: {
|
|
43
|
+
query: () => true,
|
|
44
|
+
create: ({ session }) => !!session?.userId,
|
|
45
|
+
update: ({ session }) => !!session?.userId,
|
|
46
|
+
delete: ({ session }) => !!session?.userId,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Author-only access
|
|
50
|
+
operation: {
|
|
51
|
+
query: () => true,
|
|
52
|
+
update: ({ session, item }) => item.authorId === session?.userId,
|
|
53
|
+
delete: ({ session, item }) => item.authorId === session?.userId,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Admin-only
|
|
57
|
+
operation: {
|
|
58
|
+
query: ({ session }) => session?.role === 'admin',
|
|
59
|
+
create: ({ session }) => session?.role === 'admin',
|
|
60
|
+
update: ({ session }) => session?.role === 'admin',
|
|
61
|
+
delete: ({ session }) => session?.role === 'admin',
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Filter-based access
|
|
65
|
+
operation: {
|
|
66
|
+
query: ({ session }) => ({
|
|
67
|
+
where: { authorId: { equals: session?.userId } }
|
|
68
|
+
}),
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 3. Field Mapping
|
|
73
|
+
|
|
74
|
+
**Prisma to OpenSaaS:**
|
|
75
|
+
|
|
76
|
+
| Prisma Type | OpenSaaS Field |
|
|
77
|
+
| ----------- | ------------------------------ |
|
|
78
|
+
| `String` | `text()` |
|
|
79
|
+
| `Int` | `integer()` |
|
|
80
|
+
| `Boolean` | `checkbox()` |
|
|
81
|
+
| `DateTime` | `timestamp()` |
|
|
82
|
+
| `Enum` | `select({ options: [...] })` |
|
|
83
|
+
| `Relation` | `relationship({ ref: '...' })` |
|
|
84
|
+
|
|
85
|
+
**KeystoneJS to OpenSaaS:**
|
|
86
|
+
|
|
87
|
+
| KeystoneJS Field | OpenSaaS Field |
|
|
88
|
+
| ---------------- | ---------------- |
|
|
89
|
+
| `text` | `text()` |
|
|
90
|
+
| `integer` | `integer()` |
|
|
91
|
+
| `checkbox` | `checkbox()` |
|
|
92
|
+
| `timestamp` | `timestamp()` |
|
|
93
|
+
| `select` | `select()` |
|
|
94
|
+
| `relationship` | `relationship()` |
|
|
95
|
+
| `password` | `password()` |
|
|
96
|
+
|
|
97
|
+
### 4. Database Configuration
|
|
98
|
+
|
|
99
|
+
**SQLite (Development):**
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3'
|
|
103
|
+
import Database from 'better-sqlite3'
|
|
104
|
+
|
|
105
|
+
export default config({
|
|
106
|
+
db: {
|
|
107
|
+
provider: 'sqlite',
|
|
108
|
+
url: process.env.DATABASE_URL || 'file:./dev.db',
|
|
109
|
+
prismaClientConstructor: (PrismaClient) => {
|
|
110
|
+
const db = new Database(process.env.DATABASE_URL || './dev.db')
|
|
111
|
+
const adapter = new PrismaBetterSQLite3(db)
|
|
112
|
+
return new PrismaClient({ adapter })
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**PostgreSQL (Production):**
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { PrismaPg } from '@prisma/adapter-pg'
|
|
122
|
+
import pg from 'pg'
|
|
123
|
+
|
|
124
|
+
export default config({
|
|
125
|
+
db: {
|
|
126
|
+
provider: 'postgresql',
|
|
127
|
+
url: process.env.DATABASE_URL,
|
|
128
|
+
prismaClientConstructor: (PrismaClient) => {
|
|
129
|
+
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL })
|
|
130
|
+
const adapter = new PrismaPg(pool)
|
|
131
|
+
return new PrismaClient({ adapter })
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Common Migration Challenges
|
|
138
|
+
|
|
139
|
+
### Challenge: Preserving Existing Data
|
|
140
|
+
|
|
141
|
+
**Solution:**
|
|
142
|
+
|
|
143
|
+
- Use `opensaas generate` to create Prisma schema
|
|
144
|
+
- Use `prisma db push` instead of migrations for existing databases
|
|
145
|
+
- Never use `prisma migrate dev` with existing data
|
|
146
|
+
|
|
147
|
+
### Challenge: Complex Access Control
|
|
148
|
+
|
|
149
|
+
**Solution:**
|
|
150
|
+
|
|
151
|
+
- Start with simple boolean access control
|
|
152
|
+
- Iterate to filter-based access as needed
|
|
153
|
+
- Use field-level access for sensitive data
|
|
154
|
+
|
|
155
|
+
### Challenge: Custom Field Types
|
|
156
|
+
|
|
157
|
+
**Solution:**
|
|
158
|
+
|
|
159
|
+
- Create custom field builders extending `BaseFieldConfig`
|
|
160
|
+
- Implement `getZodSchema`, `getPrismaType`, `getTypeScriptType`
|
|
161
|
+
- Register UI components for admin interface
|
|
162
|
+
|
|
163
|
+
## Migration Checklist
|
|
164
|
+
|
|
165
|
+
- [ ] Analyze existing schema
|
|
166
|
+
- [ ] Design access control patterns
|
|
167
|
+
- [ ] Create `opensaas.config.ts`
|
|
168
|
+
- [ ] Configure database adapter
|
|
169
|
+
- [ ] Run `opensaas generate`
|
|
170
|
+
- [ ] Run `prisma generate`
|
|
171
|
+
- [ ] Run `prisma db push`
|
|
172
|
+
- [ ] Test access control
|
|
173
|
+
- [ ] Verify admin UI
|
|
174
|
+
- [ ] Update application code to use context
|
|
175
|
+
- [ ] Test all CRUD operations
|
|
176
|
+
- [ ] Deploy to production
|
|
177
|
+
|
|
178
|
+
## Best Practices
|
|
179
|
+
|
|
180
|
+
1. **Start Simple**: Begin with basic access control, refine later
|
|
181
|
+
2. **Test Access Control**: Verify permissions work as expected
|
|
182
|
+
3. **Use Context Everywhere**: Replace direct Prisma calls with `context.db`
|
|
183
|
+
4. **Leverage Plugins**: Use `@opensaas/stack-auth` for authentication
|
|
184
|
+
5. **Version Control**: Commit `opensaas.config.ts` to git
|
|
185
|
+
6. **Document Decisions**: Comment complex access control logic
|
|
186
|
+
|
|
187
|
+
## Resources
|
|
188
|
+
|
|
189
|
+
- [OpenSaaS Stack Documentation](https://stack.opensaas.au/)
|
|
190
|
+
- [Migration Guide](https://stack.opensaas.au/guides/migration)
|
|
191
|
+
- [Access Control Guide](https://stack.opensaas.au/core-concepts/access-control)
|
|
192
|
+
- [Field Types](https://stack.opensaas.au/core-concepts/field-types)
|
package/.turbo/turbo-build.log
DELETED