Storage System

Storage System

Storage Overview

JSON Storage

  • Available in: Community and Pro Editions
  • Type: File-based storage
  • Format: JSON files in /stockage/json/
  • Best for: Small to medium communities
  • Pros: Simple, no database, easy backups
  • Cons: Slower for very large datasets

SQLite Storage

  • Available in: Pro Edition only
  • Type: Database storage
  • Format: SQLite database file
  • Best for: Medium to large communities
  • Pros: Better performance, SQL queries, transactions
  • Cons: Requires pdo_sqlite extension

JSON Storage

Structure

JSON storage uses organized file structure:

stockage/json/
├── config.json          # Configuration
├── users/               # User data
│   ├── user_123.json
│   └── user_456.json
├── categories/          # Categories
│   ├── category_1.json
│   └── category_2.json
├── discussions/        # Discussions
│   ├── discussion_1.json
│   └── discussion_2.json
└── posts/              # Posts
    ├── post_1.json
    └── post_2.json

File Format

Example user file (users/user_123.json):

{
  "id": "123",
  "username": "john_doe",
  "email": "[email protected]",
  "password_hash": "$2y$10$...",
  "created_at": "2025-12-25T10:00:00Z",
  "group_id": "member",
  "reputation": 100
}

Advantages

  • No Database Required - Works without database setup
  • Easy Backups - Simple file copy
  • Human Readable - JSON files are readable
  • Portable - Easy to move between servers
  • Version Control - Can use Git for versioning

Limitations

  • Performance - Slower for large datasets
  • Concurrent Access - File locking required
  • No SQL Queries - Limited query capabilities
  • File System - Depends on file system performance

SQLite Storage (Pro Edition)

Database Structure

SQLite uses standard relational database:

-- Users table
CREATE TABLE users (
    id TEXT PRIMARY KEY,
    username TEXT UNIQUE NOT NULL,
    email TEXT UNIQUE NOT NULL,
    password_hash TEXT NOT NULL,
    created_at TEXT NOT NULL,
    group_id TEXT NOT NULL,
    reputation INTEGER DEFAULT 0
);

-- Discussions table
CREATE TABLE discussions (
    id TEXT PRIMARY KEY,
    title TEXT NOT NULL,
    content TEXT NOT NULL,
    category_id TEXT NOT NULL,
    author_id TEXT NOT NULL,
    created_at TEXT NOT NULL,
    reply_count INTEGER DEFAULT 0,
    view_count INTEGER DEFAULT 0
);

Advantages

  • Performance - Faster for large datasets
  • SQL Queries - Full SQL query support
  • Transactions - ACID transactions
  • Indexes - Database indexes for speed
  • Concurrent Access - Better concurrency

Limitations

  • Pro Edition Only - Requires Pro Edition
  • Extension Required - Needs pdo_sqlite
  • Backup Complexity - Database backup required
  • Less Portable - Database file management

Choosing Storage Type

Use JSON When:

  • Small to medium community (< 10,000 users)
  • Simple setup preferred
  • Easy backups needed
  • No database experience
  • Community Edition

Use SQLite When:

  • Medium to large community (> 10,000 users)
  • Better performance needed
  • Complex queries required
  • Pro Edition available
  • Database experience

Migration Between Storage Types

Using StorageMigrator Plugin

  1. Install StorageMigrator plugin
  2. Go to Admin Panel > Storage Migrator
  3. Select target storage type
  4. Review migration preview
  5. Start migration
  6. Verify data after migration

Manual Migration

For advanced users:

  1. Backup Current Data - Full backup
  2. Export Data - Export from current storage
  3. Import Data - Import to new storage
  4. Verify - Check all data migrated
  5. Update Config - Change storage type in config

Storage Optimization

JSON Optimization

  • Regular Cleanup - Remove old/unused files
  • Archive Old Data - Move old content to archive
  • Organize Files - Keep structure organized
  • File Permissions - Set correct permissions

SQLite Optimization

-- Vacuum database
VACUUM;

-- Analyze tables
ANALYZE;

-- Reindex
REINDEX;

-- Optimize
PRAGMA optimize;

Via Admin Panel:

  • Admin Panel > Tools > Database > Optimize

Backup and Restore

JSON Backup

# Backup JSON storage
tar -czf backup-json-$(date +%Y%m%d).tar.gz stockage/json/

# Restore JSON storage
tar -xzf backup-json-20251225.tar.gz

SQLite Backup

# Backup SQLite database
sqlite3 stockage/sqlite/flatboard.db ".backup backup.db"

# Restore SQLite database
sqlite3 stockage/sqlite/flatboard.db < backup.sql

Automated Backups

Set up automated backups:

#!/bin/bash
# Backup script
DATE=$(date +%Y%m%d)
BACKUP_DIR="/backups"

# JSON backup
tar -czf $BACKUP_DIR/json-$DATE.tar.gz stockage/json/

# SQLite backup (if Pro)
if [ -f "stockage/sqlite/flatboard.db" ]; then
    sqlite3 stockage/sqlite/flatboard.db ".backup $BACKUP_DIR/sqlite-$DATE.db"
fi

Storage Maintenance

Regular Maintenance

  • Clean Old Data - Remove old/unused content
  • Optimize Storage - Run optimization commands
  • Check Disk Space - Monitor available space
  • Verify Integrity - Check data integrity

Cleanup Commands

# Clean old cache
php app/Cli/console.php cleanup:cache

# Clean empty discussions
php app/Cli/console.php cleanup:empty-discussions

# Clean old storage
php app/Cli/console.php cleanup:storage

Troubleshooting

Storage Issues

JSON:

  • Check file permissions
  • Verify disk space
  • Check for file locks
  • Review error logs

SQLite:

  • Check database file permissions
  • Verify pdo_sqlite extension
  • Check database integrity
  • Review error logs

Performance Issues

JSON:

  • Consider migrating to SQLite
  • Optimize file structure
  • Archive old data
  • Increase server resources

SQLite:

  • Add indexes
  • Optimize queries
  • Vacuum database
  • Consider JSON for small sites

Best Practices

General

  • Regular Backups - Backup storage regularly
  • Monitor Space - Watch disk usage
  • Optimize Regularly - Run optimization
  • Test Restores - Test backup restoration

JSON Specific

  • Organize Files - Keep structure clean
  • Archive Old Data - Move old content
  • Set Permissions - Correct file permissions
  • Monitor Performance - Watch for slowdowns

SQLite Specific

  • Regular VACUUM - Vacuum database regularly
  • Use Indexes - Add indexes for queries
  • Optimize Queries - Write efficient queries
  • Monitor Size - Watch database growth

Resources

Last updated: February 23, 2026