Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5123dbd69e | ||
|
|
e14a987bf3 |
+1
-1
@@ -97,7 +97,7 @@ websitedev/
|
|||||||
│ │ ├── collections/ # Payload Collections (LegalPages, Partners, Media, ContactSubmissions, Users)
|
│ │ ├── collections/ # Payload Collections (LegalPages, Partners, Media, ContactSubmissions, Users)
|
||||||
│ │ ├── payload.config.ts # Payload CMS konfiguráció
|
│ │ ├── payload.config.ts # Payload CMS konfiguráció
|
||||||
│ │ ├── content/ # RÉGI JSON rendszer — csak migrációs seed + teszt-fixture (MITHOME-91/93/96)
|
│ │ ├── content/ # RÉGI JSON rendszer — csak migrációs seed + teszt-fixture (MITHOME-91/93/96)
|
||||||
│ │ ├── lib/ # payload-content.ts (Local API adapter), content-transfer, Logger
|
│ │ ├── lib/ # payload-content.ts (Local API adapter), Logger
|
||||||
│ │ ├── config/ # Statikus site konfiguráció
|
│ │ ├── config/ # Statikus site konfiguráció
|
||||||
│ │ └── types/ # TypeScript típusdefiníciók
|
│ │ └── types/ # TypeScript típusdefiníciók
|
||||||
│ └── public/ # Statikus fájlok
|
│ └── public/ # Statikus fájlok
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ A Macen nincs Docker; a dev stack az llmdev szerveren fut, a teszt a Macről a W
|
|||||||
2. `rsync -az --delete --exclude node_modules --exclude .next --exclude .git --exclude media --exclude '.env*' ./proto ./docker ./docker-compose.dev.yml sadmin@10.8.0.1:projects/websitedev-dev/`
|
2. `rsync -az --delete --exclude node_modules --exclude .next --exclude .git --exclude media --exclude '.env*' ./proto ./docker ./docker-compose.dev.yml sadmin@10.8.0.1:projects/websitedev-dev/`
|
||||||
3. A szerveren: `docker compose -f docker-compose.dev.yml up -d --build`, majd `docker exec mozdit-app-dev npx payload migrate` (dev módban a migráció nem fut magától).
|
3. A szerveren: `docker compose -f docker-compose.dev.yml up -d --build`, majd `docker exec mozdit-app-dev npx payload migrate` (dev módban a migráció nem fut magától).
|
||||||
4. Alagút: `ssh -N -L 127.0.0.1:8080:127.0.0.1:8080 -L 127.0.0.1:5433:127.0.0.1:5433 -L 127.0.0.1:3012:127.0.0.1:3012 -L 127.0.0.1:3100:127.0.0.1:3100 sadmin@10.8.0.1`
|
4. Alagút: `ssh -N -L 127.0.0.1:8080:127.0.0.1:8080 -L 127.0.0.1:5433:127.0.0.1:5433 -L 127.0.0.1:3012:127.0.0.1:3012 -L 127.0.0.1:3100:127.0.0.1:3100 sadmin@10.8.0.1`
|
||||||
5. Tartalom: `DATABASE_URI=postgresql://mozdit_web:devpassword@127.0.0.1:5433/mozdit_web PAYLOAD_SECRET=… node --import tsx scripts/transfer-content.ts import <csomag.json>`
|
5. Tartalom: `DATABASE_URI=postgresql://mozdit_web:devpassword@127.0.0.1:5433/mozdit_web PAYLOAD_SECRET=… npm run migrate:content` (a `src/content` seedből, Local API-n át)
|
||||||
6. `npm run test:integration` és `E2E_APP_URL=http://localhost:8080 npm run test:e2e`
|
6. `npm run test:integration` és `E2E_APP_URL=http://localhost:8080 npm run test:e2e`
|
||||||
7. Takarítás: `docker compose -f docker-compose.dev.yml down -v`, a mappa és a build-image törlése.
|
7. Takarítás: `docker compose -f docker-compose.dev.yml down -v`, a mappa és a build-image törlése.
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ description: Deployment munkafolyamata — lokális teszttől a stagingen át a
|
|||||||
|
|
||||||
- **Nincs Dokploy / registry push** — a deploy natív Docker Compose-zal, a szerveren buildelve történik.
|
- **Nincs Dokploy / registry push** — a deploy natív Docker Compose-zal, a szerveren buildelve történik.
|
||||||
- **Környezetenként külön compose fájl**: `docker-compose.staging.yml` (app: 127.0.0.1:8081, saját PostgreSQL) és `docker-compose.prod.yml` (app: 8080). A két környezet ugyanazon a hoston, külön hálózaton és volume-mal fut.
|
- **Környezetenként külön compose fájl**: `docker-compose.staging.yml` (app: 127.0.0.1:8081, saját PostgreSQL) és `docker-compose.prod.yml` (app: 8080). A két környezet ugyanazon a hoston, külön hálózaton és volume-mal fut.
|
||||||
- **Környezeti változók**: kötelező `.env.staging` / `.env.production` fájlból jönnek (minta: `.env.staging.example`, `.env.production.example`). Bizalmas értékeknek (POSTGRES_PASSWORD, PAYLOAD_SECRET, az átállás idejére MONGO_ROOT_PASSWORD) **nincs fallback** — hiányzó env hangosan hibázik.
|
- **Környezeti változók**: kötelező `.env.staging` / `.env.production` fájlból jönnek (minta: `.env.staging.example`, `.env.production.example`). Bizalmas értékeknek (POSTGRES_PASSWORD, PAYLOAD_SECRET) **nincs fallback** — hiányzó env hangosan hibázik.
|
||||||
- **Staging megkülönböztetés**: a `NEXT_PUBLIC_DEPLOY_ENV=staging` build arg amber banner-t jelenít meg a weboldalon.
|
- **Staging megkülönböztetés**: a `NEXT_PUBLIC_DEPLOY_ENV=staging` build arg amber banner-t jelenít meg a weboldalon.
|
||||||
|
|
||||||
## Előfeltételek
|
## Előfeltételek
|
||||||
@@ -64,7 +64,7 @@ A szabad portot a használat előtt be kell jegyezni a portregiszterbe (`~/Proje
|
|||||||
A `proto/src/migrations/` alatti Payload migrációk a `postgresAdapter({ prodMigrations })` révén **az app konténer indulásakor automatikusan lefutnak** (`NODE_ENV=production`, stagingen és productionben is). A lefutottakat a `payload_migrations` tábla tartja nyilván, ezért minden migráció csak egyszer fut. A lefutást az app-log mutatja (`Migrating: …` / `Migrated: …`).
|
A `proto/src/migrations/` alatti Payload migrációk a `postgresAdapter({ prodMigrations })` révén **az app konténer indulásakor automatikusan lefutnak** (`NODE_ENV=production`, stagingen és productionben is). A lefutottakat a `payload_migrations` tábla tartja nyilván, ezért minden migráció csak egyszer fut. A lefutást az app-log mutatja (`Migrating: …` / `Migrated: …`).
|
||||||
|
|
||||||
- **Új migráció:** `npm run migrate:create <név>` (proto/), egy futó PostgreSQL-re mutató `DATABASE_URI`-vel. A séma csak migrációval változik; a generált fájlt kézzel nem szerkesztjük.
|
- **Új migráció:** `npm run migrate:create <név>` (proto/), egy futó PostgreSQL-re mutató `DATABASE_URI`-vel. A séma csak migrációval változik; a generált fájlt kézzel nem szerkesztjük.
|
||||||
- **Mentés:** a `deploy.sh` **a build előtt automatikusan ment**: `pg_dump -Fc` → `~/backups/mozdit-<env>-<időbélyeg>-pre-deploy.pgdump`, az átállás idejére a MongoDB-t is (`.archive`), 600-as jogosultsággal.
|
- **Mentés:** a `deploy.sh` **a build előtt automatikusan ment**: `pg_dump -Fc` → `~/backups/mozdit-<env>-<időbélyeg>-pre-deploy.pgdump` 600-as jogosultsággal.
|
||||||
|
|
||||||
## Tartalom publikálása (Payload admin)
|
## Tartalom publikálása (Payload admin)
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,6 @@
|
|||||||
POSTGRES_USER=mozdit_web
|
POSTGRES_USER=mozdit_web
|
||||||
POSTGRES_PASSWORD=changeme
|
POSTGRES_PASSWORD=changeme
|
||||||
|
|
||||||
# MongoDB — MITHOME-136: csak az átállás idejére (visszaút és a tartalom-
|
|
||||||
# átvitel forrása); egy kiadás múlva törlendő. Az app már nem használja.
|
|
||||||
MONGO_ROOT_USER=admin
|
|
||||||
MONGO_ROOT_PASSWORD=changeme
|
|
||||||
|
|
||||||
# Payload CMS (MITHOME-86) — generálj egyedi, erős titkot ehhez a
|
# Payload CMS (MITHOME-86) — generálj egyedi, erős titkot ehhez a
|
||||||
# környezethez (pl. `openssl rand -hex 32`); ne ossz meg értéket másik
|
# környezethez (pl. `openssl rand -hex 32`); ne ossz meg értéket másik
|
||||||
# environmenttel.
|
# environmenttel.
|
||||||
|
|||||||
@@ -7,11 +7,6 @@
|
|||||||
POSTGRES_USER=mozdit_web
|
POSTGRES_USER=mozdit_web
|
||||||
POSTGRES_PASSWORD=changeme
|
POSTGRES_PASSWORD=changeme
|
||||||
|
|
||||||
# MongoDB — MITHOME-136: csak az átállás idejére (visszaút és a tartalom-
|
|
||||||
# átvitel forrása); egy kiadás múlva törlendő. Az app már nem használja.
|
|
||||||
MONGO_ROOT_USER=admin
|
|
||||||
MONGO_ROOT_PASSWORD=changeme
|
|
||||||
|
|
||||||
# Payload CMS (MITHOME-86) — generálj egyedi, erős titkot ehhez a
|
# Payload CMS (MITHOME-86) — generálj egyedi, erős titkot ehhez a
|
||||||
# környezethez (pl. `openssl rand -hex 32`); ne ossz meg értéket másik
|
# környezethez (pl. `openssl rand -hex 32`); ne ossz meg értéket másik
|
||||||
# environmenttel.
|
# environmenttel.
|
||||||
|
|||||||
@@ -53,3 +53,4 @@ proto/test-results/
|
|||||||
|
|
||||||
# Más projektbe kerül (PLATFM) — lokálisan marad
|
# Más projektbe kerül (PLATFM) — lokálisan marad
|
||||||
/docs/PLATFM-1-*.md
|
/docs/PLATFM-1-*.md
|
||||||
|
.opencode/
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ websitedev/
|
|||||||
│ ├── content/ # RÉGI JSON rendszer — csak migrációs seed + teszt-fixture (MITHOME-91/93/96)
|
│ ├── content/ # RÉGI JSON rendszer — csak migrációs seed + teszt-fixture (MITHOME-91/93/96)
|
||||||
│ │ ├── common.json
|
│ │ ├── common.json
|
||||||
│ │ └── pages/
|
│ │ └── pages/
|
||||||
│ ├── lib/ # payload-content.ts (Local API adapter), content-transfer, Logger
|
│ ├── lib/ # payload-content.ts (Local API adapter), Logger
|
||||||
│ ├── config/ # Statikus site konfiguráció
|
│ ├── config/ # Statikus site konfiguráció
|
||||||
│ └── types/ # TypeScript típusok
|
│ └── types/ # TypeScript típusok
|
||||||
├── docs/ # Projekt dokumentáció (Magyar)
|
├── docs/ # Projekt dokumentáció (Magyar)
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ Az alkalmazás a Compose-hálózaton csatlakozik:
|
|||||||
DATABASE_URI=postgresql://mozdit_web:devpassword@postgres:5432/mozdit_web
|
DATABASE_URI=postgresql://mozdit_web:devpassword@postgres:5432/mozdit_web
|
||||||
```
|
```
|
||||||
|
|
||||||
A séma csak migrációval változik (`npm run migrate:create <név>`); a fejlesztői „push” ki van kapcsolva. Tartalom egy friss adatbázisba: `node --import tsx scripts/transfer-content.ts import <csomag.json>`.
|
A séma csak migrációval változik (`npm run migrate:create <név>`); a fejlesztői „push” ki van kapcsolva. Tartalom egy friss adatbázisba: `npm run migrate:content` (a `src/content` seedből)..
|
||||||
|
|
||||||
## 🛠️ Fejlesztési Parancsok
|
## 🛠️ Fejlesztési Parancsok
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ Modern Next.js weboldal a mozdIT Bt. számára — webtárhely, email- és DNS-s
|
|||||||
## Stack
|
## Stack
|
||||||
|
|
||||||
- **Frontend**: Next.js 15 (Turbopack), React 19, TypeScript, Tailwind CSS 4
|
- **Frontend**: Next.js 15 (Turbopack), React 19, TypeScript, Tailwind CSS 4
|
||||||
- **CMS**: Payload CMS (self-hosted, `/admin`), MongoDB adapter, draft/publish + verziózás, hu/en lokalizáció
|
- **CMS**: Payload CMS (self-hosted, `/admin`), PostgreSQL adapter, draft/publish + verziózás, hu/en lokalizáció
|
||||||
- **Tartalom**: Payload Globals/Collections (a korábbi JSON-alapú content rendszer, `proto/src/content/`, csak a migrációs script forrásaként és teszt-fixture-ként él tovább — MITHOME-91/93)
|
- **Tartalom**: Payload Globals/Collections (a korábbi JSON-alapú content rendszer, `proto/src/content/`, csak a migrációs script forrásaként és teszt-fixture-ként él tovább — MITHOME-91/93)
|
||||||
- **Backend**: Next.js API routes, MongoDB
|
- **Backend**: Next.js API routes, PostgreSQL
|
||||||
- **Tesztelés**: Jest, React Testing Library, Playwright (smoke)
|
- **Tesztelés**: Jest, React Testing Library, Playwright (smoke)
|
||||||
- **Deploy**: natív Docker Compose (`deploy.sh`) + Gitea Actions nélkül, lokálisan vezérelt
|
- **Deploy**: natív Docker Compose (`deploy.sh`) + Gitea Actions nélkül, lokálisan vezérelt
|
||||||
- **Naplózás/monitoring**: Winston strukturált szerveroldali logok stdout/stderr-re; központi Loki/Grafana gyűjtés külön Hosting-infrastruktúra, plusz `scripts/security-scan.sh` (ntfy riasztással)
|
- **Naplózás/monitoring**: Winston strukturált szerveroldali logok stdout/stderr-re; központi Loki/Grafana gyűjtés külön Hosting-infrastruktúra, plusz `scripts/security-scan.sh` (ntfy riasztással)
|
||||||
@@ -51,7 +51,7 @@ továbbra is a meglévő bugfix workflow-t követhetik.
|
|||||||
./deploy.sh production # éles (szerveren, staging ellenőrzése után)
|
./deploy.sh production # éles (szerveren, staging ellenőrzése után)
|
||||||
```
|
```
|
||||||
|
|
||||||
A Payload admin (`/admin`) draft/publish + verziózás munkafolyamata (MITHOME-92) nem jár git commit-tal vagy automatikus deployjal — a tartalom közvetlenül a MongoDB-be íródik. Kódváltozás (Globals/Collections séma, frontend) továbbra is a fenti git-alapú deploy folyamaton megy át. Részletek: `.agent/workflows/deploy.md`.
|
A Payload admin (`/admin`) draft/publish + verziózás munkafolyamata (MITHOME-92) nem jár git commit-tal vagy automatikus deployjal — a tartalom közvetlenül a PostgreSQL-be íródik. Kódváltozás (Globals/Collections séma, frontend) továbbra is a fenti git-alapú deploy folyamaton megy át. Részletek: `.agent/workflows/deploy.md`.
|
||||||
|
|
||||||
## Tartalomkezelés
|
## Tartalomkezelés
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ fi
|
|||||||
# 2b2. Adatbázis-mentés — build ELŐTT (MITHOME-111, MITHOME-136)
|
# 2b2. Adatbázis-mentés — build ELŐTT (MITHOME-111, MITHOME-136)
|
||||||
# WHY: a prodMigrations induláskor sémát módosíthat; egy hibás kiadás után
|
# WHY: a prodMigrations induláskor sémát módosíthat; egy hibás kiadás után
|
||||||
# a deploy előtti mentésből kell tudni visszaállni. Ami fut, azt mentjük:
|
# a deploy előtti mentésből kell tudni visszaállni. Ami fut, azt mentjük:
|
||||||
# PostgreSQL (pg_dump, egyedi formátum) és — az átállás idejére — MongoDB.
|
# PostgreSQL (pg_dump, egyedi formátum).
|
||||||
CONTAINER_ENV="$ENV"
|
CONTAINER_ENV="$ENV"
|
||||||
[ "$ENV" = "production" ] && CONTAINER_ENV="prod"
|
[ "$ENV" = "production" ] && CONTAINER_ENV="prod"
|
||||||
BACKUP_DIR="$HOME/backups"
|
BACKUP_DIR="$HOME/backups"
|
||||||
@@ -75,12 +75,6 @@ if docker ps --format '{{.Names}}' | grep -qx "mozdit-postgres-${CONTAINER_ENV}"
|
|||||||
chmod 600 "$PG_BACKUP"
|
chmod 600 "$PG_BACKUP"
|
||||||
echo "💾 PostgreSQL-mentés: $PG_BACKUP"
|
echo "💾 PostgreSQL-mentés: $PG_BACKUP"
|
||||||
fi
|
fi
|
||||||
if docker ps --format '{{.Names}}' | grep -qx "mozdit-mongodb-${CONTAINER_ENV}"; then
|
|
||||||
MONGO_BACKUP="$BACKUP_DIR/mozdit-${ENV}-${STAMP}-pre-deploy.archive"
|
|
||||||
docker exec "mozdit-mongodb-${CONTAINER_ENV}" sh -c 'mongodump --quiet --username "$MONGO_INITDB_ROOT_USERNAME" --password "$MONGO_INITDB_ROOT_PASSWORD" --authenticationDatabase admin --db mozdit --archive' > "$MONGO_BACKUP"
|
|
||||||
chmod 600 "$MONGO_BACKUP"
|
|
||||||
echo "💾 MongoDB-mentés: $MONGO_BACKUP"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 2c. Port-ellenőrzés — build ELŐTT, hogy egy ütközés ne egy teljes build után
|
# 2c. Port-ellenőrzés — build ELŐTT, hogy egy ütközés ne egy teljes build után
|
||||||
# derüljön ki. A saját projekt (újraindítandó) konténerei által foglalt port
|
# derüljön ki. A saját projekt (újraindítandó) konténerei által foglalt port
|
||||||
|
|||||||
@@ -76,30 +76,9 @@ services:
|
|||||||
- mozdit-network
|
- mozdit-network
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
# MongoDB — MITHOME-136: no longer used by the app. Kept for one release as
|
|
||||||
# the rollback path and the source of the one-off content transfer
|
|
||||||
# (proto/scripts/transfer-content.ts); remove afterwards (tasks 4.3).
|
|
||||||
mongodb:
|
|
||||||
image: mongo:7.0
|
|
||||||
container_name: mozdit-mongodb-prod
|
|
||||||
ports:
|
|
||||||
- "127.0.0.1:27018:27017" # Belső port, nem publikus az internet felé
|
|
||||||
environment:
|
|
||||||
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER:-admin}
|
|
||||||
# No weak default password: a missing value must fail the container loudly.
|
|
||||||
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
|
|
||||||
- MONGO_INITDB_DATABASE=mozdit
|
|
||||||
volumes:
|
|
||||||
- mongodb_data_prod:/data/db
|
|
||||||
networks:
|
|
||||||
- mozdit-network
|
|
||||||
restart: always
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data_prod:
|
postgres_data_prod:
|
||||||
driver: local
|
driver: local
|
||||||
mongodb_data_prod:
|
|
||||||
driver: local
|
|
||||||
media_data_prod:
|
media_data_prod:
|
||||||
driver: local
|
driver: local
|
||||||
|
|
||||||
|
|||||||
@@ -80,30 +80,9 @@ services:
|
|||||||
- mozdit-network-staging
|
- mozdit-network-staging
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
# MongoDB — MITHOME-136: no longer used by the app. Kept for one release as
|
|
||||||
# the rollback path and the source of the one-off content transfer
|
|
||||||
# (proto/scripts/transfer-content.ts); remove afterwards (tasks 4.3).
|
|
||||||
mongodb:
|
|
||||||
image: mongo:7.0
|
|
||||||
container_name: mozdit-mongodb-staging
|
|
||||||
ports:
|
|
||||||
- "127.0.0.1:27019:27017" # Belső port, nem ütközik a prod 27018-cal
|
|
||||||
environment:
|
|
||||||
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER:-admin}
|
|
||||||
# No weak default password: a missing value must fail the container loudly.
|
|
||||||
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
|
|
||||||
- MONGO_INITDB_DATABASE=mozdit
|
|
||||||
volumes:
|
|
||||||
- mongodb_data_staging:/data/db
|
|
||||||
networks:
|
|
||||||
- mozdit-network-staging
|
|
||||||
restart: always
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data_staging:
|
postgres_data_staging:
|
||||||
driver: local
|
driver: local
|
||||||
mongodb_data_staging:
|
|
||||||
driver: local
|
|
||||||
media_data_staging:
|
media_data_staging:
|
||||||
driver: local
|
driver: local
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
// MongoDB initialization script for development environment
|
|
||||||
// This script runs when the MongoDB container starts for the first time
|
|
||||||
|
|
||||||
// Switch to the mozdit database
|
|
||||||
db = db.getSiblingDB('mozdit');
|
|
||||||
|
|
||||||
// Create collections with initial data
|
|
||||||
db.createCollection('site_config');
|
|
||||||
db.createCollection('contact_submissions');
|
|
||||||
db.createCollection('users');
|
|
||||||
|
|
||||||
// Insert initial site configuration
|
|
||||||
db.site_config.insertOne({
|
|
||||||
type: 'site_config',
|
|
||||||
environment: 'development',
|
|
||||||
data: {
|
|
||||||
general: {
|
|
||||||
name: 'mozdIT Bt.',
|
|
||||||
description: 'Professzionális webhosting, email szolgáltatás és DNS adminisztráció',
|
|
||||||
url: 'http://localhost:3000',
|
|
||||||
locale: 'hu-HU'
|
|
||||||
},
|
|
||||||
contact: {
|
|
||||||
email: 'info@mozdit.hu',
|
|
||||||
address: 'Budapest, Magyarország'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
lastModified: new Date(),
|
|
||||||
createdAt: new Date()
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create indexes for better performance
|
|
||||||
db.contact_submissions.createIndex({ "email": 1 });
|
|
||||||
db.contact_submissions.createIndex({ "timestamp": -1 });
|
|
||||||
db.site_config.createIndex({ "type": 1, "environment": 1 }, { unique: true });
|
|
||||||
|
|
||||||
// Create a development user (optional)
|
|
||||||
db.users.insertOne({
|
|
||||||
username: 'dev',
|
|
||||||
email: 'dev@mozdit.hu',
|
|
||||||
role: 'admin',
|
|
||||||
createdAt: new Date(),
|
|
||||||
isActive: true
|
|
||||||
});
|
|
||||||
|
|
||||||
print('MongoDB initialized successfully for development environment');
|
|
||||||
print('Database: mozdit');
|
|
||||||
print('Collections created: site_config, contact_submissions, users');
|
|
||||||
print('Initial data inserted');
|
|
||||||
@@ -2,43 +2,6 @@
|
|||||||
|
|
||||||
// JEST MOCKS - must be set up before importing any modules that use them
|
// JEST MOCKS - must be set up before importing any modules that use them
|
||||||
|
|
||||||
// Mock MongoDB - fix MongoClient to work properly
|
|
||||||
const mockAdmin = {
|
|
||||||
ping: jest.fn().mockResolvedValue({ ok: 1 })
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockDb = {
|
|
||||||
collection: jest.fn().mockReturnValue({
|
|
||||||
findOne: jest.fn().mockResolvedValue(null),
|
|
||||||
replaceOne: jest.fn().mockResolvedValue({ acknowledged: true }),
|
|
||||||
find: jest.fn(() => ({
|
|
||||||
toArray: jest.fn().mockResolvedValue([])
|
|
||||||
})),
|
|
||||||
insertOne: jest.fn().mockResolvedValue({ acknowledged: true, insertedId: 'test-id' }),
|
|
||||||
insertMany: jest.fn().mockResolvedValue({ acknowledged: true, insertedIds: { 0: 'test-id' } }),
|
|
||||||
updateOne: jest.fn().mockResolvedValue({ acknowledged: true, matchedCount: 1, modifiedCount: 1 }),
|
|
||||||
updateMany: jest.fn().mockResolvedValue({ acknowledged: true, matchedCount: 2, modifiedCount: 2 }),
|
|
||||||
deleteOne: jest.fn().mockResolvedValue({ acknowledged: true, deletedCount: 1 }),
|
|
||||||
deleteMany: jest.fn().mockResolvedValue({ acknowledged: true, deletedCount: 2 }),
|
|
||||||
bulkWrite: jest.fn().mockResolvedValue({ acknowledged: true, insertedCount: 0, matchedCount: 0, modifiedCount: 0, deletedCount: 0, upsertedCount: 0, upsertedIds: {} })
|
|
||||||
}),
|
|
||||||
admin: jest.fn().mockReturnValue(mockAdmin)
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockClient = {
|
|
||||||
connect: jest.fn().mockResolvedValue({}),
|
|
||||||
close: jest.fn().mockResolvedValue(undefined),
|
|
||||||
db: jest.fn().mockImplementation((dbName) => mockDb)
|
|
||||||
}
|
|
||||||
|
|
||||||
jest.mock('mongodb', () => ({
|
|
||||||
MongoClient: jest.fn().mockImplementation(() => mockClient)
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Mock environment variables for tests
|
|
||||||
process.env.MONGODB_URI = 'mongodb://localhost:27017/test'
|
|
||||||
process.env.MONGODB_DB = 'test'
|
|
||||||
|
|
||||||
// Mock Winston logger - will be overridden by individual test files if needed
|
// Mock Winston logger - will be overridden by individual test files if needed
|
||||||
jest.mock('winston', () => ({
|
jest.mock('winston', () => ({
|
||||||
transports: {
|
transports: {
|
||||||
@@ -250,8 +213,6 @@ global.NextResponse = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set up environment variables for tests
|
// Set up environment variables for tests
|
||||||
process.env.MONGODB_URI = 'mongodb://localhost:27017/test'
|
|
||||||
process.env.MONGODB_DB = 'test'
|
|
||||||
process.env.NODE_ENV = 'test'
|
process.env.NODE_ENV = 'test'
|
||||||
process.env.NEXT_PUBLIC_CONTACT_EMAIL = 'info@mozdit.hu'
|
process.env.NEXT_PUBLIC_CONTACT_EMAIL = 'info@mozdit.hu'
|
||||||
process.env.NEXT_PUBLIC_SITE_URL = 'https://localhost:3000'
|
process.env.NEXT_PUBLIC_SITE_URL = 'https://localhost:3000'
|
||||||
|
|||||||
Generated
+2
-263
@@ -8,13 +8,10 @@
|
|||||||
"name": "proto",
|
"name": "proto",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@payloadcms/db-mongodb": "^3.88.0",
|
|
||||||
"@payloadcms/db-postgres": "^3.88.0",
|
"@payloadcms/db-postgres": "^3.88.0",
|
||||||
"@payloadcms/next": "^3.88.0",
|
"@payloadcms/next": "^3.88.0",
|
||||||
"@payloadcms/richtext-lexical": "^3.88.0",
|
"@payloadcms/richtext-lexical": "^3.88.0",
|
||||||
"graphql": "^16.14.2",
|
"graphql": "^16.14.2",
|
||||||
"mongodb": "^6.5",
|
|
||||||
"mongoose": "^8.2",
|
|
||||||
"next": "^16.3.4",
|
"next": "^16.3.4",
|
||||||
"payload": "^3.88.0",
|
"payload": "^3.88.0",
|
||||||
"react": "19.1.0",
|
"react": "19.1.0",
|
||||||
@@ -3396,15 +3393,6 @@
|
|||||||
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@mongodb-js/saslprep": {
|
|
||||||
"version": "1.3.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.3.0.tgz",
|
|
||||||
"integrity": "sha512-zlayKCsIjYb7/IdfqxorK5+xUMyi4vOKcFy10wKJYc63NSdKI8mNME+uJqfatkPmOSMMUiojrL58IePKBm3gvQ==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"sparse-bitfield": "^3.0.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@napi-rs/wasm-runtime": {
|
"node_modules/@napi-rs/wasm-runtime": {
|
||||||
"version": "0.2.12",
|
"version": "0.2.12",
|
||||||
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-0.2.12.tgz",
|
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-0.2.12.tgz",
|
||||||
@@ -3611,43 +3599,6 @@
|
|||||||
"node": ">=12.4.0"
|
"node": ">=12.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@payloadcms/db-mongodb": {
|
|
||||||
"version": "3.88.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@payloadcms/db-mongodb/-/db-mongodb-3.88.0.tgz",
|
|
||||||
"integrity": "sha512-bjXWm7DvUQYLCTe3zJ9Pr57gEX5pQOtH+SgAhJBhh2fMYy/bE7pLf0DJG8z1E6N9Z8b1EX3kWkE1bhTYnR5Gxg==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"mongoose": "8.24.1",
|
|
||||||
"mongoose-paginate-v2": "1.9.4",
|
|
||||||
"prompts": "2.4.2",
|
|
||||||
"uuid": "13.0.2"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"payload": "3.88.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@payloadcms/db-mongodb/node_modules/mongoose": {
|
|
||||||
"version": "8.24.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.24.1.tgz",
|
|
||||||
"integrity": "sha512-UpHBA0l5kHyKJQFjmBaFYQFo5sgz1DK0TRqDkOyBLYbqiIbKKhIvBpHWBXqeo0rgW4kGI1UhhAw+kTQZoj1BdA==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"bson": "^6.10.4",
|
|
||||||
"kareem": "2.6.3",
|
|
||||||
"mongodb": "~6.20.0",
|
|
||||||
"mpath": "0.9.0",
|
|
||||||
"mquery": "5.0.0",
|
|
||||||
"ms": "2.1.3",
|
|
||||||
"sift": "17.1.3"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.20.1"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "opencollective",
|
|
||||||
"url": "https://opencollective.com/mongoose"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@payloadcms/db-postgres": {
|
"node_modules/@payloadcms/db-postgres": {
|
||||||
"version": "3.88.0",
|
"version": "3.88.0",
|
||||||
"resolved": "https://registry.npmjs.org/@payloadcms/db-postgres/-/db-postgres-3.88.0.tgz",
|
"resolved": "https://registry.npmjs.org/@payloadcms/db-postgres/-/db-postgres-3.88.0.tgz",
|
||||||
@@ -4923,27 +4874,12 @@
|
|||||||
"integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==",
|
"integrity": "sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/webidl-conversions": {
|
|
||||||
"version": "7.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz",
|
|
||||||
"integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/@types/whatwg-mimetype": {
|
"node_modules/@types/whatwg-mimetype": {
|
||||||
"version": "3.0.2",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/whatwg-mimetype/-/whatwg-mimetype-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/whatwg-mimetype/-/whatwg-mimetype-3.0.2.tgz",
|
||||||
"integrity": "sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA==",
|
"integrity": "sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/whatwg-url": {
|
|
||||||
"version": "11.0.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz",
|
|
||||||
"integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/webidl-conversions": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@types/winston": {
|
"node_modules/@types/winston": {
|
||||||
"version": "2.4.4",
|
"version": "2.4.4",
|
||||||
"resolved": "https://registry.npmjs.org/@types/winston/-/winston-2.4.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/winston/-/winston-2.4.4.tgz",
|
||||||
@@ -6168,15 +6104,6 @@
|
|||||||
"node-int64": "^0.4.0"
|
"node-int64": "^0.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/bson": {
|
|
||||||
"version": "6.10.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/bson/-/bson-6.10.4.tgz",
|
|
||||||
"integrity": "sha512-WIsKqkSC0ABoBJuT1LEX+2HEvNmNKKgnTAyd0fL8qzK4SH2i9NXg+t08YtdZp/V9IZ33cxe3iV4yM0qg8lMQng==",
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.20.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/bson-objectid": {
|
"node_modules/bson-objectid": {
|
||||||
"version": "2.0.4",
|
"version": "2.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/bson-objectid/-/bson-objectid-2.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/bson-objectid/-/bson-objectid-2.0.4.tgz",
|
||||||
@@ -11227,15 +11154,6 @@
|
|||||||
"node": ">=4.0"
|
"node": ">=4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/kareem": {
|
|
||||||
"version": "2.6.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.3.tgz",
|
|
||||||
"integrity": "sha512-C3iHfuGUXK2u8/ipq9LfjFfXFxAZMQJJq7vLS45r3D9Y2xQ/m4S8zaR4zMLFWh9AsNPXmcFfUDhTEO8UIC/V6Q==",
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=12.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/keyv": {
|
"node_modules/keyv": {
|
||||||
"version": "4.5.4",
|
"version": "4.5.4",
|
||||||
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
|
"resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
|
||||||
@@ -11848,12 +11766,6 @@
|
|||||||
"integrity": "sha512-rkpe71W0N0c0Xz6QD0eJETuWAJGnJ9afsl1srmwPrI+yBCkge5EycXXbYRyvL29zZVUWQCY7InPRCv3GDXuZNw==",
|
"integrity": "sha512-rkpe71W0N0c0Xz6QD0eJETuWAJGnJ9afsl1srmwPrI+yBCkge5EycXXbYRyvL29zZVUWQCY7InPRCv3GDXuZNw==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/memory-pager": {
|
|
||||||
"version": "1.5.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz",
|
|
||||||
"integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/merge-stream": {
|
"node_modules/merge-stream": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
||||||
@@ -12501,166 +12413,6 @@
|
|||||||
"marked": "14.0.0"
|
"marked": "14.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mongodb": {
|
|
||||||
"version": "6.20.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.20.0.tgz",
|
|
||||||
"integrity": "sha512-Tl6MEIU3K4Rq3TSHd+sZQqRBoGlFsOgNrH5ltAcFBV62Re3Fd+FcaVf8uSEQFOJ51SDowDVttBTONMfoYWrWlQ==",
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"dependencies": {
|
|
||||||
"@mongodb-js/saslprep": "^1.3.0",
|
|
||||||
"bson": "^6.10.4",
|
|
||||||
"mongodb-connection-string-url": "^3.0.2"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.20.1"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@aws-sdk/credential-providers": "^3.188.0",
|
|
||||||
"@mongodb-js/zstd": "^1.1.0 || ^2.0.0",
|
|
||||||
"gcp-metadata": "^5.2.0",
|
|
||||||
"kerberos": "^2.0.1",
|
|
||||||
"mongodb-client-encryption": ">=6.0.0 <7",
|
|
||||||
"snappy": "^7.3.2",
|
|
||||||
"socks": "^2.7.1"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"@aws-sdk/credential-providers": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"@mongodb-js/zstd": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"gcp-metadata": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"kerberos": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"mongodb-client-encryption": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"snappy": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"socks": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mongodb-connection-string-url": {
|
|
||||||
"version": "3.0.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.2.tgz",
|
|
||||||
"integrity": "sha512-rMO7CGo/9BFwyZABcKAWL8UJwH/Kc2x0g72uhDWzG48URRax5TCIcJ7Rc3RZqffZzO/Gwff/jyKwCU9TN8gehA==",
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/whatwg-url": "^11.0.2",
|
|
||||||
"whatwg-url": "^14.1.0 || ^13.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mongodb-connection-string-url/node_modules/tr46": {
|
|
||||||
"version": "5.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.1.tgz",
|
|
||||||
"integrity": "sha512-hdF5ZgjTqgAntKkklYw0R03MG2x/bSzTtkxmIRw/sTNV8YXsCJ1tfLAX23lhxhHJlEf3CRCOCGGWw3vI3GaSPw==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"punycode": "^2.3.1"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mongodb-connection-string-url/node_modules/whatwg-url": {
|
|
||||||
"version": "14.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz",
|
|
||||||
"integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"tr46": "^5.1.0",
|
|
||||||
"webidl-conversions": "^7.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=18"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mongoose": {
|
|
||||||
"version": "8.24.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.24.4.tgz",
|
|
||||||
"integrity": "sha512-DoV8hYy5ssoh/j99rhYzeS2BLLcLJZ+EGQYfe/Ln+yMorBy0wgKdlwJBj59zJ1N0MnEKQypbeqUYFB0FVThmYg==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"bson": "^6.10.4",
|
|
||||||
"kareem": "2.6.3",
|
|
||||||
"mongodb": "~6.20.0",
|
|
||||||
"mpath": "0.9.0",
|
|
||||||
"mquery": "5.0.0",
|
|
||||||
"ms": "2.1.3",
|
|
||||||
"sift": "17.1.3"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.20.1"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"type": "opencollective",
|
|
||||||
"url": "https://opencollective.com/mongoose"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mongoose-lean-virtuals": {
|
|
||||||
"version": "1.1.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongoose-lean-virtuals/-/mongoose-lean-virtuals-1.1.1.tgz",
|
|
||||||
"integrity": "sha512-8chOqpVE3bcoWT2pIgcJeIZlXaOfQCavZgQZF4qytUtjRBqsNMyzUoR16qdw9XL2kC478N8iA8z0AA+NSS0d1A==",
|
|
||||||
"license": "Apache 2.0",
|
|
||||||
"dependencies": {
|
|
||||||
"mpath": "^0.8.4"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=16.20.1"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"mongoose": ">=5.11.10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mongoose-lean-virtuals/node_modules/mpath": {
|
|
||||||
"version": "0.8.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.8.4.tgz",
|
|
||||||
"integrity": "sha512-DTxNZomBcTWlrMW76jy1wvV37X/cNNxPW1y2Jzd4DZkAaC5ZGsm8bfGfNOthcDuRJujXLqiuS6o3Tpy0JEoh7g==",
|
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mongoose-paginate-v2": {
|
|
||||||
"version": "1.9.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/mongoose-paginate-v2/-/mongoose-paginate-v2-1.9.4.tgz",
|
|
||||||
"integrity": "sha512-0LOsVEQmjrbJKVDi/IvFEhIezmuRjUE4loGgslv57j9nK/NMC+mbKT0QnaPSPpib4lByKVBcy3VbDa1TvlHZjA==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"mongoose-lean-virtuals": "^1.1.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mpath": {
|
|
||||||
"version": "0.9.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz",
|
|
||||||
"integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==",
|
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mquery": {
|
|
||||||
"version": "5.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz",
|
|
||||||
"integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"debug": "4.x"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=14.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/ms": {
|
"node_modules/ms": {
|
||||||
"version": "2.1.3",
|
"version": "2.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
|
||||||
@@ -13856,6 +13608,7 @@
|
|||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",
|
||||||
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
|
"integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==",
|
||||||
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
@@ -14631,12 +14384,6 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/sift": {
|
|
||||||
"version": "17.1.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz",
|
|
||||||
"integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/signal-exit": {
|
"node_modules/signal-exit": {
|
||||||
"version": "3.0.7",
|
"version": "3.0.7",
|
||||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
|
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
|
||||||
@@ -14724,15 +14471,6 @@
|
|||||||
"source-map": "^0.6.0"
|
"source-map": "^0.6.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/sparse-bitfield": {
|
|
||||||
"version": "3.0.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz",
|
|
||||||
"integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"memory-pager": "^1.0.2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/split2": {
|
"node_modules/split2": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
|
||||||
@@ -15889,6 +15627,7 @@
|
|||||||
"version": "7.0.0",
|
"version": "7.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz",
|
||||||
"integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==",
|
"integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==",
|
||||||
|
"dev": true,
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
|
|||||||
@@ -39,13 +39,10 @@
|
|||||||
"migrate:status": "payload migrate:status"
|
"migrate:status": "payload migrate:status"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@payloadcms/db-mongodb": "^3.88.0",
|
|
||||||
"@payloadcms/db-postgres": "^3.88.0",
|
"@payloadcms/db-postgres": "^3.88.0",
|
||||||
"@payloadcms/next": "^3.88.0",
|
"@payloadcms/next": "^3.88.0",
|
||||||
"@payloadcms/richtext-lexical": "^3.88.0",
|
"@payloadcms/richtext-lexical": "^3.88.0",
|
||||||
"graphql": "^16.14.2",
|
"graphql": "^16.14.2",
|
||||||
"mongodb": "^6.5",
|
|
||||||
"mongoose": "^8.2",
|
|
||||||
"next": "^16.3.4",
|
"next": "^16.3.4",
|
||||||
"payload": "^3.88.0",
|
"payload": "^3.88.0",
|
||||||
"react": "19.1.0",
|
"react": "19.1.0",
|
||||||
|
|||||||
@@ -1,199 +0,0 @@
|
|||||||
/**
|
|
||||||
* MITHOME-136: one-off content transfer MongoDB → PostgreSQL, in two steps
|
|
||||||
* so that only one Payload instance runs per process and the bundle can be
|
|
||||||
* reviewed (and reused to seed a fresh database).
|
|
||||||
*
|
|
||||||
* export — reads through the shared config with the MongoDB adapter:
|
|
||||||
* MONGODB_URI=… PAYLOAD_SECRET=… node --import tsx scripts/transfer-content.ts export <bundle.json> [--no-submissions] [--media-dir media]
|
|
||||||
* import — writes through the site's config (PostgreSQL); refuses a non-empty target:
|
|
||||||
* DATABASE_URI=… PAYLOAD_SECRET=… node --import tsx scripts/transfer-content.ts import <bundle.json>
|
|
||||||
*
|
|
||||||
* The bundle holds every global and collection except users (the admin is
|
|
||||||
* re-created by deploy.sh), the published state in both locales, open drafts,
|
|
||||||
* and the upload files. It contains personal data (contact submissions) unless
|
|
||||||
* exported with --no-submissions: keep it out of git, chmod 600.
|
|
||||||
*/
|
|
||||||
import fs from 'fs'
|
|
||||||
import path from 'path'
|
|
||||||
import {
|
|
||||||
buildConfig,
|
|
||||||
commitTransaction,
|
|
||||||
createLocalReq,
|
|
||||||
getPayload,
|
|
||||||
initTransaction,
|
|
||||||
killTransaction,
|
|
||||||
type CollectionConfig,
|
|
||||||
type Payload,
|
|
||||||
type PayloadRequest,
|
|
||||||
} from 'payload'
|
|
||||||
import { mongooseAdapter } from '@payloadcms/db-mongodb'
|
|
||||||
|
|
||||||
import { sharedConfig } from '../src/payload.shared'
|
|
||||||
import { bundleCounts, localeData, upgradeDoc, type BundleDoc, type IdMap, type TransferBundle } from '../src/lib/content-transfer'
|
|
||||||
|
|
||||||
type Data = Record<string, unknown>
|
|
||||||
type Slug = Parameters<Payload['find']>[0]['collection']
|
|
||||||
type GlobalSlug = Parameters<Payload['findGlobal']>[0]['slug']
|
|
||||||
|
|
||||||
const [mode, bundlePath, ...flags] = process.argv.slice(2)
|
|
||||||
const flag = (name: string) => flags.includes(name)
|
|
||||||
const option = (name: string, fallback: string) => {
|
|
||||||
const i = flags.indexOf(name)
|
|
||||||
return i >= 0 && flags[i + 1] ? flags[i + 1] : fallback
|
|
||||||
}
|
|
||||||
|
|
||||||
const collections = (sharedConfig.collections ?? []).filter((c) => c.slug !== 'users')
|
|
||||||
const globals = sharedConfig.globals ?? []
|
|
||||||
const hasDrafts = (c: { versions?: unknown }) => typeof c.versions === 'object' && c.versions !== null && 'drafts' in c.versions && Boolean((c.versions as { drafts?: unknown }).drafts)
|
|
||||||
const LOCALES = ['hu', 'en'] as const
|
|
||||||
|
|
||||||
async function exportBundle(file: string) {
|
|
||||||
const config = buildConfig({ ...sharedConfig, db: mongooseAdapter({ url: process.env.MONGODB_URI || '' }) })
|
|
||||||
const payload = await getPayload({ config })
|
|
||||||
const mediaDir = path.resolve(option('--media-dir', 'media'))
|
|
||||||
const bundle: TransferBundle = { exportedAt: new Date().toISOString(), source: 'mongodb', globals: {}, collections: {}, files: {} }
|
|
||||||
|
|
||||||
for (const g of globals) {
|
|
||||||
const slug = g.slug as GlobalSlug
|
|
||||||
const published = (await payload.findGlobal({ slug, locale: 'all', depth: 0 })) as unknown as Data
|
|
||||||
const latest = (await payload.findGlobal({ slug, locale: 'all', depth: 0, draft: true })) as unknown as Data
|
|
||||||
bundle.globals[slug] = { published, ...(hasDrafts(g) && latest._status === 'draft' ? { draft: latest } : {}) }
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const c of collections) {
|
|
||||||
if (c.slug === 'contact-submissions' && flag('--no-submissions')) continue
|
|
||||||
const slug = c.slug as Slug
|
|
||||||
const published = (await payload.find({ collection: slug, locale: 'all', depth: 0, pagination: false })).docs as unknown as Data[]
|
|
||||||
const latest = hasDrafts(c)
|
|
||||||
? ((await payload.find({ collection: slug, locale: 'all', depth: 0, pagination: false, draft: true })).docs as unknown as Data[])
|
|
||||||
: []
|
|
||||||
const byId = new Map<string, BundleDoc>(published.map((doc) => [String(doc.id), { published: doc }]))
|
|
||||||
for (const doc of latest) {
|
|
||||||
const entry = byId.get(String(doc.id))
|
|
||||||
if (doc._status !== 'draft') continue
|
|
||||||
if (entry) entry.draft = doc
|
|
||||||
else byId.set(String(doc.id), { published: { ...doc }, draft: doc }) // never published
|
|
||||||
}
|
|
||||||
bundle.collections[slug] = [...byId.values()]
|
|
||||||
|
|
||||||
if (c.upload) {
|
|
||||||
for (const { published: doc } of bundle.collections[slug]) {
|
|
||||||
const name = String(doc.filename)
|
|
||||||
bundle.files[name] = { mimeType: String(doc.mimeType), base64: fs.readFileSync(path.join(mediaDir, name)).toString('base64') }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(file, JSON.stringify(bundle, null, 2), { mode: 0o600 })
|
|
||||||
payload.logger.info(`MITHOME-136 export: ${JSON.stringify(bundleCounts(bundle))} → ${file}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function assertEmptyTarget(payload: Payload) {
|
|
||||||
for (const c of collections) {
|
|
||||||
const { totalDocs } = await payload.count({ collection: c.slug as Slug })
|
|
||||||
if (totalDocs > 0) throw new Error(`Target is not empty: ${c.slug} has ${totalDocs} document(s). Nothing was written.`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function importCollection(payload: Payload, req: PayloadRequest, c: CollectionConfig, docs: BundleDoc[], bundle: TransferBundle, ids: IdMap) {
|
|
||||||
const slug = c.slug as Slug
|
|
||||||
const drafts = hasDrafts(c)
|
|
||||||
for (const raw of docs) {
|
|
||||||
const entry: BundleDoc = { published: upgradeDoc(c.slug, raw.published), ...(raw.draft ? { draft: upgradeDoc(c.slug, raw.draft) } : {}) }
|
|
||||||
const oldId = String(entry.published.id)
|
|
||||||
const neverPublished = entry.published._status === 'draft'
|
|
||||||
const status = drafts ? { _status: neverPublished ? 'draft' : 'published' } : {}
|
|
||||||
const file = c.upload
|
|
||||||
? (() => {
|
|
||||||
const name = String(entry.published.filename)
|
|
||||||
const stored = bundle.files[name]
|
|
||||||
const data = Buffer.from(stored.base64, 'base64')
|
|
||||||
return { data, mimetype: stored.mimeType, name, size: data.length }
|
|
||||||
})()
|
|
||||||
: undefined
|
|
||||||
|
|
||||||
const created = await payload.create({
|
|
||||||
req,
|
|
||||||
collection: slug,
|
|
||||||
locale: 'hu',
|
|
||||||
data: { ...localeData(c.fields, entry.published, 'hu', ids), ...status } as never,
|
|
||||||
...(file ? { file, overwriteExistingFiles: true } : {}),
|
|
||||||
draft: neverPublished,
|
|
||||||
})
|
|
||||||
ids.set(oldId, String(created.id))
|
|
||||||
await payload.update({
|
|
||||||
req,
|
|
||||||
collection: slug,
|
|
||||||
id: created.id,
|
|
||||||
locale: 'en',
|
|
||||||
data: { ...localeData(c.fields, entry.published, 'en', ids), ...status } as never,
|
|
||||||
draft: neverPublished,
|
|
||||||
})
|
|
||||||
if (entry.draft && !neverPublished) {
|
|
||||||
for (const locale of LOCALES) {
|
|
||||||
await payload.update({ req, collection: slug, id: created.id, locale, draft: true, data: localeData(c.fields, entry.draft, locale, ids) as never })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function importBundle(file: string) {
|
|
||||||
const bundle = JSON.parse(fs.readFileSync(file, 'utf8')) as TransferBundle
|
|
||||||
const { default: config } = await import('../src/payload.config')
|
|
||||||
const payload = await getPayload({ config })
|
|
||||||
await assertEmptyTarget(payload)
|
|
||||||
|
|
||||||
// One transaction: a failure leaves the target untouched ("change nothing").
|
|
||||||
const req = await createLocalReq({}, payload)
|
|
||||||
await initTransaction(req)
|
|
||||||
try {
|
|
||||||
const ids: IdMap = new Map()
|
|
||||||
// Uploads first, so relationships can be mapped to the new ids.
|
|
||||||
const ordered = [...collections].sort((a, b) => Number(Boolean(b.upload)) - Number(Boolean(a.upload)))
|
|
||||||
for (const c of ordered) {
|
|
||||||
await importCollection(payload, req, c, bundle.collections[c.slug] ?? [], bundle, ids)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const g of globals) {
|
|
||||||
const raw = bundle.globals[g.slug]
|
|
||||||
if (!raw) continue
|
|
||||||
const entry: BundleDoc = { published: upgradeDoc(g.slug, raw.published), ...(raw.draft ? { draft: upgradeDoc(g.slug, raw.draft) } : {}) }
|
|
||||||
const slug = g.slug as GlobalSlug
|
|
||||||
const status = hasDrafts(g) ? { _status: 'published' } : {}
|
|
||||||
for (const locale of LOCALES) {
|
|
||||||
await payload.updateGlobal({ req, slug, locale, data: { ...localeData(g.fields, entry.published, locale, ids), ...status } as never })
|
|
||||||
}
|
|
||||||
if (entry.draft) {
|
|
||||||
for (const locale of LOCALES) {
|
|
||||||
await payload.updateGlobal({ req, slug, locale, draft: true, data: localeData(g.fields, entry.draft, locale, ids) as never })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await commitTransaction(req)
|
|
||||||
} catch (error) {
|
|
||||||
await killTransaction(req)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
|
|
||||||
const counts: Record<string, number> = {}
|
|
||||||
for (const c of collections) counts[c.slug] = (await payload.count({ collection: c.slug as Slug })).totalDocs
|
|
||||||
payload.logger.info(`MITHOME-136 import: expected ${JSON.stringify(bundleCounts(bundle))}, got ${JSON.stringify(counts)}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
if (!bundlePath || (mode !== 'export' && mode !== 'import')) {
|
|
||||||
console.error('Usage: transfer-content.ts export|import <bundle.json> [--no-submissions] [--media-dir DIR]')
|
|
||||||
process.exit(2)
|
|
||||||
}
|
|
||||||
if (mode === 'export') await exportBundle(bundlePath)
|
|
||||||
else await importBundle(bundlePath)
|
|
||||||
process.exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
main().catch((error) => {
|
|
||||||
// Payload validation errors carry the failing fields in data.errors.
|
|
||||||
const details = (error as { data?: { collection?: string; errors?: unknown } })?.data
|
|
||||||
console.error('MITHOME-136 transfer failed:', error instanceof Error ? error.message : error)
|
|
||||||
if (details) console.error(JSON.stringify(details, null, 2))
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
@@ -45,7 +45,7 @@ function sanitizeInput(input: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WHY: explicit length caps — the CMS has a body limit but this public endpoint
|
// WHY: explicit length caps — the CMS has a body limit but this public endpoint
|
||||||
// does not; without them an arbitrarily large message could be written to Mongo.
|
// does not; without them an arbitrarily large message could be written to the database.
|
||||||
const MAX_LENGTHS = {
|
const MAX_LENGTHS = {
|
||||||
name: 100,
|
name: 100,
|
||||||
email: 254,
|
email: 254,
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ const { mockLoggerError } = jest.requireMock('@/lib/logger')
|
|||||||
// relative specifier at transform time (Jest itself doesn't understand
|
// relative specifier at transform time (Jest itself doesn't understand
|
||||||
// tsconfig `paths`), so a `jest.mock('@payload-config', ...)` never actually
|
// tsconfig `paths`), so a `jest.mock('@payload-config', ...)` never actually
|
||||||
// intercepts what route.ts ends up requiring — it silently falls through to
|
// intercepts what route.ts ends up requiring — it silently falls through to
|
||||||
// the real proto/src/payload.config.ts (mongooseAdapter, Users/LegalPages/etc
|
// the real proto/src/payload.config.ts (postgresAdapter, Users/LegalPages/etc
|
||||||
// imports), which needs a live MongoDB and PAYLOAD_SECRET, exactly what these
|
// imports), which needs a live PostgreSQL and PAYLOAD_SECRET, exactly what these
|
||||||
// tests avoid. The route only ever passes this value through to the (also
|
// tests avoid. The route only ever passes this value through to the (also
|
||||||
// mocked) getPayload(), so its actual shape doesn't matter here.
|
// mocked) getPayload(), so its actual shape doesn't matter here.
|
||||||
jest.mock('../../../payload.config', () => ({ __esModule: true, default: {} }))
|
jest.mock('../../../payload.config', () => ({ __esModule: true, default: {} }))
|
||||||
@@ -78,7 +78,7 @@ describe('/api/contact Unit Tests', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns a server error when persistence fails', async () => {
|
it('returns a server error when persistence fails', async () => {
|
||||||
mockCreate.mockRejectedValue(new Error('MongoDB unavailable'))
|
mockCreate.mockRejectedValue(new Error('Database unavailable'))
|
||||||
const request = {
|
const request = {
|
||||||
headers: new Headers({ 'x-forwarded-for': 'persistence-failure' }),
|
headers: new Headers({ 'x-forwarded-for': 'persistence-failure' }),
|
||||||
json: async () => validData,
|
json: async () => validData,
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
import type { Field } from 'payload'
|
|
||||||
import { bundleCounts, localeData, upgradeDoc } from './content-transfer'
|
|
||||||
|
|
||||||
const FIELDS: Field[] = [
|
|
||||||
{ name: 'name', type: 'text' },
|
|
||||||
{ name: 'title', type: 'text', localized: true },
|
|
||||||
{
|
|
||||||
name: 'hero',
|
|
||||||
type: 'group',
|
|
||||||
fields: [
|
|
||||||
{ name: 'title', type: 'text', localized: true },
|
|
||||||
{ name: 'icon', type: 'text' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'items',
|
|
||||||
type: 'array',
|
|
||||||
fields: [
|
|
||||||
{ name: 'label', type: 'text', localized: true },
|
|
||||||
{ name: 'order', type: 'number' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ name: 'paragraphs', type: 'array', localized: true, fields: [{ name: 'value', type: 'text' }] },
|
|
||||||
{ type: 'row', fields: [{ name: 'result', type: 'text' }] },
|
|
||||||
{ name: 'logo', type: 'upload', relationTo: 'media' },
|
|
||||||
]
|
|
||||||
|
|
||||||
const DOC = {
|
|
||||||
id: 'old-doc',
|
|
||||||
_id: 'old-doc',
|
|
||||||
__v: 0,
|
|
||||||
_status: 'published',
|
|
||||||
updatedAt: '2026-09-29T10:00:00.000Z',
|
|
||||||
createdAt: '2026-09-01T08:00:00.000Z',
|
|
||||||
name: 'mIT Start',
|
|
||||||
title: { hu: 'Cím', en: 'Title' },
|
|
||||||
hero: { title: { hu: 'Hős', en: 'Hero' }, icon: '🔥' },
|
|
||||||
items: [{ id: 'row1', label: { hu: 'Egy', en: 'One' }, order: 1 }],
|
|
||||||
paragraphs: { hu: [{ id: 'p1', value: 'Első' }, { id: 'p2', value: 'Második' }], en: [{ id: 'p3', value: 'First' }] },
|
|
||||||
result: 'ok',
|
|
||||||
logo: { id: 'old-media', filename: 'logo.png' },
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('content transfer (MITHOME-136)', () => {
|
|
||||||
it('should split a locale-all document into Hungarian data', () => {
|
|
||||||
expect(localeData(FIELDS, DOC, 'hu')).toEqual({
|
|
||||||
name: 'mIT Start',
|
|
||||||
title: 'Cím',
|
|
||||||
hero: { title: 'Hős', icon: '🔥' },
|
|
||||||
items: [{ id: 'row1', label: 'Egy', order: 1 }],
|
|
||||||
paragraphs: [{ id: 'p1', value: 'Első' }, { id: 'p2', value: 'Második' }],
|
|
||||||
result: 'ok',
|
|
||||||
logo: 'old-media',
|
|
||||||
createdAt: '2026-09-01T08:00:00.000Z',
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should keep array row ids so the English update hits the same rows', () => {
|
|
||||||
const en = localeData(FIELDS, DOC, 'en')
|
|
||||||
expect(en.items).toEqual([{ id: 'row1', label: 'One', order: 1 }])
|
|
||||||
expect(en.paragraphs).toEqual([{ id: 'p3', value: 'First' }])
|
|
||||||
expect(en.title).toBe('Title')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should map upload ids to the new documents', () => {
|
|
||||||
const ids = new Map([['old-media', 'new-media']])
|
|
||||||
expect(localeData(FIELDS, DOC, 'hu', ids).logo).toBe('new-media')
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should drop system fields and leave missing fields out', () => {
|
|
||||||
const data = localeData(FIELDS, { name: 'x', _status: 'draft', globalType: 'home' }, 'hu')
|
|
||||||
expect(data).toEqual({ name: 'x' })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should count the documents of a bundle', () => {
|
|
||||||
expect(
|
|
||||||
bundleCounts({
|
|
||||||
exportedAt: '',
|
|
||||||
source: '',
|
|
||||||
globals: { home: { published: {} } },
|
|
||||||
collections: { partners: [{ published: {} }, { published: {} }] },
|
|
||||||
files: {},
|
|
||||||
}),
|
|
||||||
).toEqual({ partners: 2, 'global:home': 1 })
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should move the legal section anchor out of the row id, unique per page', () => {
|
|
||||||
const doc = { slug: 'adatvedelem', sections: [{ id: 'bevezetes', title: { hu: 'Bevezetés' } }] }
|
|
||||||
expect(upgradeDoc('legal-pages', doc).sections).toEqual([
|
|
||||||
{ id: 'adatvedelem-bevezetes', anchor: 'bevezetes', title: { hu: 'Bevezetés' } },
|
|
||||||
])
|
|
||||||
expect(upgradeDoc('legal-pages', upgradeDoc('legal-pages', doc))).toEqual(upgradeDoc('legal-pages', doc))
|
|
||||||
expect(upgradeDoc('partners', doc)).toBe(doc)
|
|
||||||
})
|
|
||||||
it('should move the Home usps/items key out of the row id, keeping the row id', () => {
|
|
||||||
const home = { about: { usps: [{ id: 'egyszeru', icon: '🎯' }] }, services: { items: [{ id: 'hosting' }] } }
|
|
||||||
const upgraded = upgradeDoc('home', home) as { about: { usps: unknown[] }; services: { items: unknown[] } }
|
|
||||||
expect(upgraded.about.usps).toEqual([{ id: 'egyszeru', key: 'egyszeru', icon: '🎯' }])
|
|
||||||
expect(upgraded.services.items).toEqual([{ id: 'hosting', key: 'hosting' }])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,112 +0,0 @@
|
|||||||
/**
|
|
||||||
* MITHOME-136: pure helpers of the one-off MongoDB → PostgreSQL content
|
|
||||||
* transfer (scripts/transfer-content.ts).
|
|
||||||
*
|
|
||||||
* The export reads every document with `locale: 'all'`, so each localized
|
|
||||||
* field arrives as `{ hu, en }`. Payload writes one locale at a time, so the
|
|
||||||
* import splits a document into per-locale data using the field config:
|
|
||||||
* localized fields take the locale's value, groups/unnamed rows recurse,
|
|
||||||
* array rows keep their ids (the English update must hit the same rows), and
|
|
||||||
* upload/relationship ids are mapped from the old to the new id.
|
|
||||||
*/
|
|
||||||
import type { Field } from 'payload'
|
|
||||||
|
|
||||||
export type Locale = 'hu' | 'en'
|
|
||||||
type Data = Record<string, unknown>
|
|
||||||
export type IdMap = Map<string, string>
|
|
||||||
|
|
||||||
const SYSTEM_KEYS = new Set(['id', '_id', '__v', 'globalType', 'updatedAt', '_status'])
|
|
||||||
|
|
||||||
const isObject = (value: unknown): value is Data =>
|
|
||||||
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
||||||
|
|
||||||
function mapId(value: unknown, ids: IdMap): unknown {
|
|
||||||
if (value === null || value === undefined) return value
|
|
||||||
const id = isObject(value) ? value.id : value
|
|
||||||
return typeof id === 'string' ? (ids.get(id) ?? id) : id
|
|
||||||
}
|
|
||||||
|
|
||||||
function splitFields(fields: readonly Field[], source: Data, locale: Locale, ids: IdMap, out: Data): Data {
|
|
||||||
for (const field of fields) {
|
|
||||||
if (!('name' in field) || !field.name) {
|
|
||||||
// row / collapsible: unnamed wrappers keep their fields on the same level
|
|
||||||
if ('fields' in field) splitFields(field.fields, source, locale, ids, out)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (!(field.name in source)) continue
|
|
||||||
const raw = source[field.name]
|
|
||||||
const value = 'localized' in field && field.localized && isObject(raw) ? raw[locale] : raw
|
|
||||||
|
|
||||||
if (field.type === 'group' && isObject(value)) {
|
|
||||||
out[field.name] = splitFields(field.fields, value, locale, ids, {})
|
|
||||||
} else if (field.type === 'array' && Array.isArray(value)) {
|
|
||||||
out[field.name] = value.map((row) =>
|
|
||||||
isObject(row) ? { ...(row.id ? { id: row.id } : {}), ...splitFields(field.fields, row, locale, ids, {}) } : row,
|
|
||||||
)
|
|
||||||
} else if (field.type === 'upload' || field.type === 'relationship') {
|
|
||||||
out[field.name] = Array.isArray(value) ? value.map((v) => mapId(v, ids)) : mapId(value, ids)
|
|
||||||
} else {
|
|
||||||
out[field.name] = value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shape changes between the MongoDB schema and the current one, applied to an
|
|
||||||
* exported document before it is split by locale.
|
|
||||||
* - legal-pages: the section anchor was the array row `id`; it is now the
|
|
||||||
* `anchor` field, and the row id must be unique across all pages (it is a
|
|
||||||
* table-wide primary key in PostgreSQL), so it becomes `<slug>-<anchor>`.
|
|
||||||
* - home (global): the usps/items row `id` was the editable key; it is now the
|
|
||||||
* `key` field (MITHOME-138). The row id stays, so both locales hit the same row.
|
|
||||||
*/
|
|
||||||
const withKey = (rows: unknown) =>
|
|
||||||
Array.isArray(rows)
|
|
||||||
? rows.map((row) => (isObject(row) && typeof row.id === 'string' && !('key' in row) ? { ...row, key: row.id } : row))
|
|
||||||
: rows
|
|
||||||
|
|
||||||
export function upgradeDoc(collection: string, doc: Data): Data {
|
|
||||||
if (collection === 'home') {
|
|
||||||
const about = isObject(doc.about) ? { ...doc.about, usps: withKey(doc.about.usps) } : doc.about
|
|
||||||
const services = isObject(doc.services) ? { ...doc.services, items: withKey(doc.services.items) } : doc.services
|
|
||||||
return { ...doc, about, services }
|
|
||||||
}
|
|
||||||
if (collection !== 'legal-pages' || !Array.isArray(doc.sections)) return doc
|
|
||||||
return {
|
|
||||||
...doc,
|
|
||||||
sections: doc.sections.map((section) =>
|
|
||||||
isObject(section) && typeof section.id === 'string' && !('anchor' in section)
|
|
||||||
? { ...section, id: `${doc.slug}-${section.id}`, anchor: section.id }
|
|
||||||
: section,
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The data of one locale, ready for `create`/`update` with that `locale`. */
|
|
||||||
export function localeData(fields: readonly Field[], doc: Data, locale: Locale, ids: IdMap = new Map()): Data {
|
|
||||||
const out = splitFields(fields, doc, locale, ids, {})
|
|
||||||
for (const key of SYSTEM_KEYS) delete out[key]
|
|
||||||
// Keep the original creation time (contact submission retention).
|
|
||||||
if (typeof doc.createdAt === 'string') out.createdAt = doc.createdAt
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Count documents per collection/global in an export bundle. */
|
|
||||||
export function bundleCounts(bundle: TransferBundle): Record<string, number> {
|
|
||||||
const counts: Record<string, number> = {}
|
|
||||||
for (const [slug, docs] of Object.entries(bundle.collections)) counts[slug] = docs.length
|
|
||||||
for (const slug of Object.keys(bundle.globals)) counts[`global:${slug}`] = 1
|
|
||||||
return counts
|
|
||||||
}
|
|
||||||
|
|
||||||
export type BundleDoc = { published: Data; draft?: Data }
|
|
||||||
|
|
||||||
export type TransferBundle = {
|
|
||||||
exportedAt: string
|
|
||||||
source: string
|
|
||||||
globals: Record<string, BundleDoc>
|
|
||||||
collections: Record<string, BundleDoc[]>
|
|
||||||
/** Upload files by filename, base64 — the bundle is self-contained. */
|
|
||||||
files: Record<string, { mimeType: string; base64: string }>
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
* MITHOME-96 — Payload collection/global config tesztek.
|
* MITHOME-96 — Payload collection/global config tesztek.
|
||||||
*
|
*
|
||||||
* WHY nem a teljes payload.config.ts-t importáljuk: az a valódi `payload` és
|
* WHY nem a teljes payload.config.ts-t importáljuk: az a valódi `payload` és
|
||||||
* `@payloadcms/db-mongodb` csomagokat importálja értékként (nem csak
|
* `@payloadcms/db-postgres` csomagokat importálja értékként (nem csak
|
||||||
* típusként), amik ESM-only, natív node_modules-forrást futtatnak — Jest
|
* típusként), amik ESM-only, natív node_modules-forrást futtatnak — Jest
|
||||||
* (a next/jest transzformmal is) nem tudja lefordítani őket anélkül, hogy a
|
* (a next/jest transzformmal is) nem tudja lefordítani őket anélkül, hogy a
|
||||||
* teljes payload-függőségi fát is a transformIgnorePatterns kivételévé
|
* teljes payload-függőségi fát is a transformIgnorePatterns kivételévé
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
* module` a payload csomag saját forrásából). Az egyes Collection/Global
|
* module` a payload csomag saját forrásából). Az egyes Collection/Global
|
||||||
* fájlok viszont csak `import type` formában hivatkoznak a `payload`
|
* fájlok viszont csak `import type` formában hivatkoznak a `payload`
|
||||||
* csomagra — ez típus-only import, a build kitörli, így ezek a fájlok
|
* csomagra — ez típus-only import, a build kitörli, így ezek a fájlok
|
||||||
* önmagukban, gyors unit tesztként importálhatók, élő MongoDB/PAYLOAD_SECRET
|
* önmagukban, gyors unit tesztként importálhatók, élő PostgreSQL/PAYLOAD_SECRET
|
||||||
* nélkül. Ez fedi le a ticket "Payload config tesztek" részét; a Local API
|
* nélkül. Ez fedi le a ticket "Payload config tesztek" részét; a Local API
|
||||||
* ellen futó, élő adatbázist igénylő tesztek külön (integrációs) fájlban
|
* ellen futó, élő adatbázist igénylő tesztek külön (integrációs) fájlban
|
||||||
* vannak — lásd src/__tests__/payload-local-api.test.ts.
|
* vannak — lásd src/__tests__/payload-local-api.test.ts.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* WHY separate: the site runs on PostgreSQL (src/payload.config.ts), but the
|
* WHY separate: the site runs on PostgreSQL (src/payload.config.ts), but the
|
||||||
* one-off content transfer (scripts/transfer-content.ts) must read the same
|
* one-off content transfer (scripts/transfer-content.ts) must read the same
|
||||||
* collections and globals through the MongoDB adapter. Both configs are built
|
* collections and globals through the database adapter. Both configs are built
|
||||||
* from this object, so the content model cannot drift between them.
|
* from this object, so the content model cannot drift between them.
|
||||||
*/
|
*/
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|||||||
Reference in New Issue
Block a user