# `PhoenixKit.Migrations.Postgres.V20`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.165/lib/phoenix_kit/migrations/postgres/v20.ex#L1)

PhoenixKit V20 Migration: Distributed File Storage System

Adds comprehensive distributed file storage with multi-location redundancy,
automatic variant generation, and smart volume selection.

## Changes

### Storage Buckets Table (phoenix_kit_buckets)
- Stores storage provider configurations (local, S3, B2, R2)
- Priority-based volume selection (0 = random/emptiest, >0 = specific priority)
- Tracks max capacity and credentials per bucket

### Files Table (phoenix_kit_files)
- Original file uploads with metadata
- Supports images, videos, documents, archives
- JSONB metadata for EXIF, codec info, etc.
- Links to user for ownership tracking

### File Instances Table (phoenix_kit_file_instances)
- File variants (thumbnails, resizes, video qualities)
- Tracks processing status per variant
- One original + multiple generated variants

### File Locations Table (phoenix_kit_file_locations)
- Physical storage locations for redundancy
- Maps instances to specific buckets
- Supports 1-5 redundant copies across buckets

### Storage Dimensions Table (phoenix_kit_storage_dimensions)
- Admin-configurable dimension presets
- Seeded with defaults: thumbnail, small, medium, large, 360p, 720p, 1080p
- Applies to images, videos, or both

## Features

- **UUIDv7 Primary Keys**: Time-sortable IDs for all storage tables
- **Multi-location Redundancy**: Store files across multiple buckets
- **Smart Volume Selection**: Priority system + emptiest drive selection
- **Token-based URLs**: Secure file access preventing enumeration
- **Automatic Variants**: Generate thumbnails, resizes, video qualities
- **PostgreSQL JSONB**: Flexible metadata storage

## Settings

- `storage_redundancy_copies`: How many bucket copies (default: 1)
- `storage_auto_generate_variants`: Auto-generate thumbnails/resizes (default: true)
- `storage_default_bucket_id`: Default bucket for uploads (optional)

# `down`

Rollback the V20 migration.

# `up`

Run the V20 migration to add distributed storage system.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
