Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
93fe2f9
Remove useless modal popup
Nov 11, 2025
c53700f
Updated media details page
Nov 11, 2025
228d5ef
Made sure bucket shuffling does work when uploading files
Nov 11, 2025
ec1972d
Added storage locations in the media details page
Nov 11, 2025
d744aa0
Updated the Upload file button to cleaner layout
Nov 12, 2025
6b6fc7d
Added uploaded by to media details page
Nov 12, 2025
2ab617a
Updated the upload component to return the file id that was uploaded.
Nov 12, 2025
74d2d04
Created single public update_user_avatar that would create instances …
Nov 12, 2025
0f6019a
Added proccessing file in the upload function to create instances
Nov 12, 2025
9759e97
Updated media upload
Nov 12, 2025
e0ecbd8
Moved the process file logic
Nov 12, 2025
86d0ee6
Added avatar upload logic for the user edit page
Nov 12, 2025
1aef1ba
Mix format
Nov 12, 2025
224d84a
Updated the navbar to show the users avatar
Nov 12, 2025
bcc2abb
Fixed the uesr edit page clearing untouched fields
Nov 12, 2025
1fb683a
Merge branch 'BeamLabEU:dev' into dev
alexdont Nov 12, 2025
028ebd4
Fixed credo issues
Nov 12, 2025
a493caa
Fixed issues with user name on the user editing page
Nov 12, 2025
aa02d85
Added file instance creator on the fly
Nov 13, 2025
c197947
Making sure you can't upload duplicate files
Nov 13, 2025
b311588
Fixed username reseting when changing users timezone
Nov 13, 2025
3be961d
Added instance recreation when it has broken media
Nov 13, 2025
13ed7ce
Added maintain aspect ratio toggle feature
Nov 13, 2025
ad5c3a2
Fixed deleting of buckets
Nov 13, 2025
b1be503
Merge branch 'BeamLabEU:dev' into dev
alexdont Nov 14, 2025
31d8b56
Fixed credo issues
Nov 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions lib/phoenix_kit/migrations/postgres.ex
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ defmodule PhoenixKit.Migrations.Postgres do
- Metadata storage for additional context in audit logs
- Performance indexes for efficient querying by user, action, and date

### V23 - Session Fingerprinting ⚡ LATEST
### V23 - Session Fingerprinting
- Session fingerprinting columns (ip_address, user_agent_hash) in phoenix_kit_users_tokens
- Prevents session hijacking by detecting suspicious session usage patterns
- IP address tracking: Detects when session is used from different IP
Expand All @@ -158,18 +158,25 @@ defmodule PhoenixKit.Migrations.Postgres do
- Configurable strictness: Can log warnings or force re-authentication
- Performance indexes for efficient fingerprint verification

### V24 - File Checksum Unique Index ⚡ LATEST
- Unique index on phoenix_kit_files.checksum for O(1) duplicate detection
- Enables automatic deduplication of uploaded files
- Prevents redundant storage of identical files
- Improves performance of duplicate file lookups

## Migration Paths

### Fresh Installation (0 → Current)
Runs all migrations V01 through V23 in sequence.
Runs all migrations V01 through V24 in sequence.

### Incremental Updates
- V01 → V23: Runs V02 through V23 in sequence
- V22V23: Runs V23 only (adds session fingerprinting)
- V21V23: Runs V22 and V23 in sequence
- V20 → V23: Runs V21, V22, and V23 in sequence
- V01 → V24: Runs V02 through V24 in sequence
- V23V24: Runs V24 only (adds file checksum unique index)
- V22V24: Runs V23 and V24 in sequence
- V20 → V24: Runs V21, V22, V23, and V24 in sequence

### Rollback Support
- V24 → V23: Removes unique index on checksum
- V23 → V22: Removes session fingerprinting columns and indexes
- V22 → V21: Removes audit logging system, email orphaned events, and email metrics
- V21 → V20: Removes composite message ID index
Expand All @@ -186,14 +193,14 @@ defmodule PhoenixKit.Migrations.Postgres do

## Usage Examples

# Update to latest version (V23)
# Update to latest version (V24)
PhoenixKit.Migrations.Postgres.up(prefix: "myapp")

# Update to specific version
PhoenixKit.Migrations.Postgres.up(prefix: "myapp", version: 23)
PhoenixKit.Migrations.Postgres.up(prefix: "myapp", version: 24)

# Rollback to specific version
PhoenixKit.Migrations.Postgres.down(prefix: "myapp", version: 22)
PhoenixKit.Migrations.Postgres.down(prefix: "myapp", version: 23)

# Complete rollback
PhoenixKit.Migrations.Postgres.down(prefix: "myapp", version: 0)
Expand All @@ -211,7 +218,7 @@ defmodule PhoenixKit.Migrations.Postgres do
use Ecto.Migration

@initial_version 1
@current_version 23
@current_version 25
@default_prefix "public"

@doc false
Expand Down
69 changes: 69 additions & 0 deletions lib/phoenix_kit/migrations/postgres/v24.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
defmodule PhoenixKit.Migrations.Postgres.V24 do
@moduledoc """
PhoenixKit V24 Migration: File Checksum Unique Index

This migration adds a unique index on the checksum field of the phoenix_kit_files table
to enable efficient duplicate file detection and prevent duplicate file storage.

## Changes

### File Deduplication Support
- Adds unique index on phoenix_kit_files.checksum for O(1) duplicate lookups
- Enables automatic deduplication of uploaded files
- Prevents redundant storage of identical files

## PostgreSQL Support
- Supports PostgreSQL prefix for schema isolation
- Creates unique index for fast duplicate detection
"""
use Ecto.Migration

@doc """
Run the V24 file checksum indexing migration.

Handles existing duplicate checksums by keeping the oldest file and deleting newer duplicates.
"""
def up(%{prefix: prefix} = _opts) do
# First, remove duplicate checksums by keeping the oldest file (first inserted)
# This ensures the migration won't fail due to existing duplicates
remove_duplicate_checksums(prefix)

# Create unique index on checksum for duplicate detection
create_if_not_exists unique_index(:phoenix_kit_files, [:checksum], prefix: prefix)

# Set version comment on phoenix_kit table for version tracking
execute "COMMENT ON TABLE #{prefix_table_name("phoenix_kit", prefix)} IS '24'"
end

@doc """
Rollback the V24 file checksum indexing migration.
"""
def down(%{prefix: prefix} = _opts) do
# Drop unique index on checksum
drop_if_exists unique_index(:phoenix_kit_files, [:checksum], prefix: prefix)

# Update version comment on phoenix_kit table to previous version
execute "COMMENT ON TABLE #{prefix_table_name("phoenix_kit", prefix)} IS '23'"
end

# Helper function to remove duplicate checksums
# Keeps the oldest file (earliest inserted_at) and deletes newer duplicates
defp remove_duplicate_checksums(prefix) do
table_name = prefix_table_name("phoenix_kit_files", prefix)

sql = """
DELETE FROM #{table_name} f1
WHERE id NOT IN (
SELECT DISTINCT ON (checksum) id
FROM #{table_name}
ORDER BY checksum, inserted_at ASC
)
"""

execute(sql)
end

# Helper function to build table name with prefix
defp prefix_table_name(table_name, nil), do: table_name
defp prefix_table_name(table_name, prefix), do: "#{prefix}.#{table_name}"
end
54 changes: 54 additions & 0 deletions lib/phoenix_kit/migrations/postgres/v25.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
defmodule PhoenixKit.Migrations.Postgres.V25 do
@moduledoc """
PhoenixKit V25 Migration: Aspect Ratio Control for Dimensions

This migration adds support for aspect ratio preservation in dimension configuration.
Allows users to choose between maintaining aspect ratio (width only) or fixed dimensions.

## Changes

### Storage Dimensions Table (phoenix_kit_storage_dimensions)
- Adds `maintain_aspect_ratio` boolean column (default: true)
- When true: Only width is used, height is calculated to preserve aspect ratio
- When false: Both width and height are used as fixed dimensions (for thumbnails/crops)

## Features

- **Aspect Ratio Mode**: Responsive sizing with width-only specification
- **Fixed Dimension Mode**: Exact pixel dimensions for square crops/thumbnails
- **Per-Dimension Control**: Each variant can independently choose its mode
- **Default to Aspect Ratio**: All dimensions default to maintaining aspect ratio
"""
use Ecto.Migration

@doc """
Run the V25 migration to add aspect ratio control.
"""
def up(%{prefix: prefix} = _opts) do
# Add maintain_aspect_ratio column to dimensions table
alter table(:phoenix_kit_storage_dimensions, prefix: prefix) do
add :maintain_aspect_ratio, :boolean, default: true, null: false
end

# Set version comment on phoenix_kit table for version tracking
execute "COMMENT ON TABLE #{prefix_table_name("phoenix_kit", prefix)} IS '25'"
end

@doc """
Rollback the V25 migration.
"""
def down(%{prefix: prefix} = _opts) do
# Remove maintain_aspect_ratio column from dimensions table
alter table(:phoenix_kit_storage_dimensions, prefix: prefix) do
remove :maintain_aspect_ratio
end

# Update version comment on phoenix_kit table to previous version
execute "COMMENT ON TABLE #{prefix_table_name("phoenix_kit", prefix)} IS '24'"
end

# Helper functions

defp prefix_table_name(table_name, nil), do: table_name
defp prefix_table_name(table_name, prefix), do: "#{prefix}.#{table_name}"
end
Loading
Loading