- Created setup-directus-collections.js to automate the creation of tech stack collections, fields, and relations in Directus. - Created setup-directus-hobbies.js for setting up hobbies collection with translations. - Created setup-directus-projects.js for establishing projects collection with comprehensive fields and translations. - Added setup-tech-stack-directus.js to populate tech_stack_items with predefined data.
185 lines
4.4 KiB
Markdown
185 lines
4.4 KiB
Markdown
# Directus Setup & Migration Scripts
|
|
|
|
Automatische Scripts zum Erstellen und Befüllen aller Collections in Directus.
|
|
|
|
## 📦 Verfügbare Scripts
|
|
|
|
### 1. Tech Stack (✅ Bereits ausgeführt)
|
|
|
|
```bash
|
|
# Collections erstellen
|
|
node scripts/setup-directus-collections.js
|
|
|
|
# Daten migrieren
|
|
node scripts/migrate-tech-stack-to-directus.js
|
|
```
|
|
|
|
**Was erstellt wird:**
|
|
- `tech_stack_categories` (4 Kategorien: Frontend, Backend, Tools, Security)
|
|
- `tech_stack_items` (~16 Items)
|
|
- Translations (DE + EN)
|
|
|
|
---
|
|
|
|
### 2. Projects (🔥 Neu)
|
|
|
|
```bash
|
|
# Collections erstellen
|
|
node scripts/setup-directus-projects.js
|
|
|
|
# Daten aus PostgreSQL migrieren
|
|
node scripts/migrate-projects-to-directus.js
|
|
```
|
|
|
|
**Was erstellt wird:**
|
|
- `projects` Collection mit 30+ Feldern:
|
|
- Basics: slug, title, description, content
|
|
- Meta: category, difficulty, tags, technologies
|
|
- Links: github, live, image_url, demo_video
|
|
- Details: challenges, lessons_learned, future_improvements
|
|
- Performance: lighthouse scores, bundle sizes
|
|
- `projects_translations` für mehrsprachige Inhalte
|
|
- Migriert ALLE Projekte aus PostgreSQL
|
|
|
|
**Hinweis:** Läuft nur wenn Projects Collection noch nicht existiert!
|
|
|
|
---
|
|
|
|
### 3. Hobbies (🎮 Neu)
|
|
|
|
```bash
|
|
# Collections erstellen
|
|
node scripts/setup-directus-hobbies.js
|
|
|
|
# Daten migrieren
|
|
node scripts/migrate-hobbies-to-directus.js
|
|
```
|
|
|
|
**Was erstellt wird:**
|
|
- `hobbies` Collection (4 Hobbies: Self-Hosting, Gaming, Game Servers, Jogging)
|
|
- Translations (DE + EN)
|
|
|
|
---
|
|
|
|
## 🚀 Komplette Migration (alles auf einmal)
|
|
|
|
```bash
|
|
# 1. Tech Stack
|
|
node scripts/setup-directus-collections.js
|
|
node scripts/migrate-tech-stack-to-directus.js
|
|
|
|
# 2. Projects
|
|
node scripts/setup-directus-projects.js
|
|
node scripts/migrate-projects-to-directus.js
|
|
|
|
# 3. Hobbies
|
|
node scripts/setup-directus-hobbies.js
|
|
node scripts/migrate-hobbies-to-directus.js
|
|
```
|
|
|
|
**Oder als One-Liner:**
|
|
|
|
```bash
|
|
node scripts/setup-directus-collections.js && \
|
|
node scripts/migrate-tech-stack-to-directus.js && \
|
|
node scripts/setup-directus-projects.js && \
|
|
node scripts/migrate-projects-to-directus.js && \
|
|
node scripts/setup-directus-hobbies.js && \
|
|
node scripts/migrate-hobbies-to-directus.js
|
|
```
|
|
|
|
---
|
|
|
|
## ⚙️ Voraussetzungen
|
|
|
|
```bash
|
|
# Dependencies installieren
|
|
npm install node-fetch@2 dotenv @prisma/client
|
|
```
|
|
|
|
**In .env:**
|
|
```env
|
|
DIRECTUS_URL=https://cms.dk0.dev
|
|
DIRECTUS_STATIC_TOKEN=your_token_here
|
|
DATABASE_URL=postgresql://...
|
|
```
|
|
|
|
---
|
|
|
|
## 📊 Nach der Migration
|
|
|
|
### Directus Admin Panel:
|
|
|
|
- **Tech Stack:** https://cms.dk0.dev/admin/content/tech_stack_categories
|
|
- **Projects:** https://cms.dk0.dev/admin/content/projects
|
|
- **Hobbies:** https://cms.dk0.dev/admin/content/hobbies
|
|
|
|
### API Endpoints (automatisch verfügbar):
|
|
|
|
```bash
|
|
# Tech Stack
|
|
GET https://cms.dk0.dev/items/tech_stack_categories?fields=*,translations.*,items.*
|
|
|
|
# Projects
|
|
GET https://cms.dk0.dev/items/projects?fields=*,translations.*
|
|
|
|
# Hobbies
|
|
GET https://cms.dk0.dev/items/hobbies?fields=*,translations.*
|
|
```
|
|
|
|
---
|
|
|
|
## 🔄 Code-Updates nach Migration
|
|
|
|
### 1. lib/directus.ts erweitern
|
|
|
|
```typescript
|
|
// Bereits implementiert:
|
|
export async function getTechStack(locale: string)
|
|
|
|
// TODO:
|
|
export async function getProjects(locale: string)
|
|
export async function getHobbies(locale: string)
|
|
```
|
|
|
|
### 2. Components anpassen
|
|
|
|
- `About.tsx` - ✅ Bereits updated für Tech Stack
|
|
- `About.tsx` - TODO: Hobbies aus Directus laden
|
|
- `Projects.tsx` - TODO: Projects aus Directus laden
|
|
|
|
---
|
|
|
|
## 🐛 Troubleshooting
|
|
|
|
### Error: "Collection already exists"
|
|
→ Normal! Script überspringt bereits existierende Collections automatisch.
|
|
|
|
### Error: "DIRECTUS_STATIC_TOKEN not found"
|
|
→ Stelle sicher dass `.env` vorhanden ist und `require('dotenv').config()` funktioniert.
|
|
|
|
### Error: "Unauthorized" oder HTTP 403
|
|
→ Überprüfe Token-Rechte in Directus Admin → Settings → Access Tokens
|
|
|
|
### Migration findet keine Projekte
|
|
→ Stelle sicher dass PostgreSQL läuft und `DATABASE_URL` korrekt ist.
|
|
|
|
---
|
|
|
|
## 📝 Nächste Schritte
|
|
|
|
1. ✅ **Alle Scripts ausführen** (siehe oben)
|
|
2. ✅ **Verifizieren** in Directus Admin Panel
|
|
3. ⏭️ **Code updaten** (lib/directus.ts + Components)
|
|
4. ⏭️ **Testen** auf localhost
|
|
5. ⏭️ **Deployen** auf Production
|
|
|
|
---
|
|
|
|
## 💡 Pro-Tipps
|
|
|
|
- **Backups:** Exportiere Schema regelmäßig via Directus UI
|
|
- **Version Control:** Committe Schema-Files ins Git
|
|
- **Incremental:** Scripts können mehrfach ausgeführt werden (idempotent)
|
|
- **Rollback:** Lösche Collections in Directus UI falls nötig
|