Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions migrations/sql/down/add-users-profile-fields.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP INDEX IF EXISTS idx_users_deleted_at;

ALTER TABLE users
DROP COLUMN IF EXISTS deleted_at,
DROP COLUMN IF EXISTS face_embedding,
DROP COLUMN IF EXISTS display_name;
4 changes: 4 additions & 0 deletions migrations/sql/down/create-event-participants-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DROP INDEX IF EXISTS idx_event_participants_user_id;
DROP INDEX IF EXISTS idx_event_participants_event_id;

DROP TABLE IF EXISTS event_participants;
6 changes: 6 additions & 0 deletions migrations/sql/down/create-events-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP INDEX IF EXISTS idx_events_status;
DROP INDEX IF EXISTS idx_events_event_date;
DROP INDEX IF EXISTS idx_events_created_by;

DROP TABLE IF EXISTS events;
DROP TYPE IF EXISTS event_status;
4 changes: 4 additions & 0 deletions migrations/sql/down/create-face-matches-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DROP INDEX IF EXISTS idx_face_matches_user_id;
DROP INDEX IF EXISTS idx_face_matches_face_id;

DROP TABLE IF EXISTS face_matches;
4 changes: 4 additions & 0 deletions migrations/sql/down/create-notifications-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DROP INDEX IF EXISTS idx_notifications_read_at;
DROP INDEX IF EXISTS idx_notifications_user_id;

DROP TABLE IF EXISTS notifications;
4 changes: 4 additions & 0 deletions migrations/sql/down/create-photo-approvals-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DROP INDEX IF EXISTS idx_photo_approvals_user_id;
DROP INDEX IF EXISTS idx_photo_approvals_photo_id;

DROP TABLE IF EXISTS photo_approvals;
3 changes: 3 additions & 0 deletions migrations/sql/down/create-photo-faces-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP INDEX IF EXISTS idx_photo_faces_photo_id;

DROP TABLE IF EXISTS photo_faces;
6 changes: 6 additions & 0 deletions migrations/sql/down/create-photos-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP INDEX IF EXISTS idx_photos_status;
DROP INDEX IF EXISTS idx_photos_uploaded_by;
DROP INDEX IF EXISTS idx_photos_event_id;

DROP TABLE IF EXISTS photos;
DROP TYPE IF EXISTS photo_status;
5 changes: 5 additions & 0 deletions migrations/sql/down/create-processing-jobs-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DROP INDEX IF EXISTS idx_processing_jobs_status;
DROP INDEX IF EXISTS idx_processing_jobs_photo_id;

DROP TABLE IF EXISTS processing_jobs;
DROP TYPE IF EXISTS processing_job_status;
6 changes: 6 additions & 0 deletions migrations/sql/down/create-upload-requests-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP INDEX IF EXISTS idx_upload_requests_status;
DROP INDEX IF EXISTS idx_upload_requests_requested_by;
DROP INDEX IF EXISTS idx_upload_requests_event_id;

DROP TABLE IF EXISTS upload_requests;
DROP TYPE IF EXISTS upload_request_status;
4 changes: 4 additions & 0 deletions migrations/sql/down/create-user-photos-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DROP INDEX IF EXISTS idx_user_photos_photo_id;
DROP INDEX IF EXISTS idx_user_photos_user_id;

DROP TABLE IF EXISTS user_photos;
4 changes: 4 additions & 0 deletions migrations/sql/down/create_staff_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DROP INDEX IF EXISTS idx_staff_users_discord_id;

DROP TABLE IF EXISTS staff_users;
DROP TYPE IF EXISTS staff_role;
6 changes: 6 additions & 0 deletions migrations/sql/up/add-users-profile-fields.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE users
ADD COLUMN IF NOT EXISTS display_name TEXT,
ADD COLUMN IF NOT EXISTS face_embedding VECTOR(1536),
ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMPTZ;

CREATE INDEX IF NOT EXISTS idx_users_deleted_at ON users(deleted_at);
10 changes: 10 additions & 0 deletions migrations/sql/up/create-event-participants-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS event_participants (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
event_id UUID NOT NULL REFERENCES events(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
joined_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE(event_id, user_id)
);

CREATE INDEX IF NOT EXISTS idx_event_participants_event_id ON event_participants(event_id);
CREATE INDEX IF NOT EXISTS idx_event_participants_user_id ON event_participants(user_id);
16 changes: 16 additions & 0 deletions migrations/sql/up/create-events-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TYPE event_status AS ENUM ('draft', 'scheduled', 'archived');

CREATE TABLE IF NOT EXISTS events (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
event_code VARCHAR(64) NOT NULL UNIQUE,
event_date TIMESTAMPTZ NOT NULL,
status event_status NOT NULL DEFAULT 'draft',
created_by UUID NOT NULL REFERENCES staff_users(id) ON DELETE RESTRICT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
archived_at TIMESTAMPTZ
);

CREATE INDEX IF NOT EXISTS idx_events_created_by ON events(created_by);
CREATE INDEX IF NOT EXISTS idx_events_event_date ON events(event_date);
CREATE INDEX IF NOT EXISTS idx_events_status ON events(status);
10 changes: 10 additions & 0 deletions migrations/sql/up/create-face-matches-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS face_matches (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
photo_face_id UUID NOT NULL REFERENCES photo_faces(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
confidence DOUBLE PRECISION NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_face_matches_face_id ON face_matches(photo_face_id);
CREATE INDEX IF NOT EXISTS idx_face_matches_user_id ON face_matches(user_id);
11 changes: 11 additions & 0 deletions migrations/sql/up/create-notifications-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS notifications (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
type VARCHAR(64) NOT NULL,
payload JSONB NOT NULL,
read_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_notifications_user_id ON notifications(user_id);
CREATE INDEX IF NOT EXISTS idx_notifications_read_at ON notifications(read_at);
10 changes: 10 additions & 0 deletions migrations/sql/up/create-photo-approvals-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE IF NOT EXISTS photo_approvals (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
photo_id UUID NOT NULL REFERENCES photos(id) ON DELETE CASCADE,
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
decision VARCHAR(32) NOT NULL,
decided_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_photo_approvals_photo_id ON photo_approvals(photo_id);
CREATE INDEX IF NOT EXISTS idx_photo_approvals_user_id ON photo_approvals(user_id);
11 changes: 11 additions & 0 deletions migrations/sql/up/create-photo-faces-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS photo_faces (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
photo_id UUID NOT NULL REFERENCES photos(id) ON DELETE CASCADE,
face_index INT NOT NULL,
embedding VECTOR(1536),
bbox TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE(photo_id, face_index)
);

CREATE INDEX IF NOT EXISTS idx_photo_faces_photo_id ON photo_faces(photo_id);
17 changes: 17 additions & 0 deletions migrations/sql/up/create-photos-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TYPE photo_status AS ENUM ('pending', 'approved', 'rejected');

CREATE TABLE IF NOT EXISTS photos (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
event_id UUID NOT NULL REFERENCES events(id) ON DELETE CASCADE,
uploaded_by UUID REFERENCES users(id) ON DELETE SET NULL,
storage_key TEXT NOT NULL,
taken_at TIMESTAMPTZ,
day_number INT,
visibility VARCHAR(32) NOT NULL DEFAULT 'private',
status photo_status NOT NULL DEFAULT 'pending',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE INDEX IF NOT EXISTS idx_photos_event_id ON photos(event_id);
CREATE INDEX IF NOT EXISTS idx_photos_uploaded_by ON photos(uploaded_by);
CREATE INDEX IF NOT EXISTS idx_photos_status ON photos(status);
14 changes: 14 additions & 0 deletions migrations/sql/up/create-processing-jobs-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE TYPE processing_job_status AS ENUM ('pending', 'running', 'completed', 'failed');

CREATE TABLE IF NOT EXISTS processing_jobs (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
photo_id UUID NOT NULL REFERENCES photos(id) ON DELETE CASCADE,
job_type VARCHAR(64) NOT NULL,
status processing_job_status NOT NULL DEFAULT 'pending',
attempts INT NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
completed_at TIMESTAMPTZ
);

CREATE INDEX IF NOT EXISTS idx_processing_jobs_photo_id ON processing_jobs(photo_id);
CREATE INDEX IF NOT EXISTS idx_processing_jobs_status ON processing_jobs(status);
16 changes: 16 additions & 0 deletions migrations/sql/up/create-upload-requests-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TYPE upload_request_status AS ENUM ('pending', 'approved', 'rejected');

CREATE TABLE IF NOT EXISTS upload_requests (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
event_id UUID NOT NULL REFERENCES events(id) ON DELETE CASCADE,
drive_file_id TEXT NOT NULL,
requested_by UUID NOT NULL REFERENCES staff_users(id) ON DELETE RESTRICT,
approved_by UUID REFERENCES staff_users(id) ON DELETE SET NULL,
status upload_request_status NOT NULL DEFAULT 'pending',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
approved_at TIMESTAMPTZ
);

CREATE INDEX IF NOT EXISTS idx_upload_requests_event_id ON upload_requests(event_id);
CREATE INDEX IF NOT EXISTS idx_upload_requests_requested_by ON upload_requests(requested_by);
CREATE INDEX IF NOT EXISTS idx_upload_requests_status ON upload_requests(status);
11 changes: 11 additions & 0 deletions migrations/sql/up/create-user-photos-table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS user_photos (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
photo_id UUID NOT NULL REFERENCES photos(id) ON DELETE CASCADE,
visibility VARCHAR(32) NOT NULL DEFAULT 'private',
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
UNIQUE(user_id, photo_id)
);

CREATE INDEX IF NOT EXISTS idx_user_photos_user_id ON user_photos(user_id);
CREATE INDEX IF NOT EXISTS idx_user_photos_photo_id ON user_photos(photo_id);
25 changes: 25 additions & 0 deletions migrations/versions/042883327797_create_photo_faces_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""create-photo-faces-table

Revision ID: 042883327797
Revises: b29d627b8e27
Create Date: 2026-03-12 18:07:41.843182

"""
from typing import Sequence, Union

from migrations.helper import run_sql_down, run_sql_up


# revision identifiers, used by Alembic.
revision: str = '042883327797'
down_revision: Union[str, Sequence[str], None] = 'b29d627b8e27'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
run_sql_up("create-photo-faces-table")


def downgrade() -> None:
run_sql_down("create-photo-faces-table")
25 changes: 25 additions & 0 deletions migrations/versions/0952572fe9b4_create_photos_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""create-photos-table

Revision ID: 0952572fe9b4
Revises: 36c3d68f547f
Create Date: 2026-03-12 18:06:18.603970

"""
from typing import Sequence, Union

from migrations.helper import run_sql_down, run_sql_up


# revision identifiers, used by Alembic.
revision: str = '0952572fe9b4'
down_revision: Union[str, Sequence[str], None] = '36c3d68f547f'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
run_sql_up("create-photos-table")


def downgrade() -> None:
run_sql_down("create-photos-table")
25 changes: 25 additions & 0 deletions migrations/versions/127f362c99e9_create_upload_requests_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""create-upload-requests-table

Revision ID: 127f362c99e9
Revises: 78f200d4cec7
Create Date: 2026-03-12 18:08:53.285973

"""
from typing import Sequence, Union

from migrations.helper import run_sql_down, run_sql_up


# revision identifiers, used by Alembic.
revision: str = '127f362c99e9'
down_revision: Union[str, Sequence[str], None] = '78f200d4cec7'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
run_sql_up("create-upload-requests-table")


def downgrade() -> None:
run_sql_down("create-upload-requests-table")
25 changes: 25 additions & 0 deletions migrations/versions/1f6d3a37d12b_create_face_matches_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""create-face-matches-table

Revision ID: 1f6d3a37d12b
Revises: 042883327797
Create Date: 2026-03-12 18:08:08.162096

"""
from typing import Sequence, Union

from migrations.helper import run_sql_down, run_sql_up


# revision identifiers, used by Alembic.
revision: str = '1f6d3a37d12b'
down_revision: Union[str, Sequence[str], None] = '042883327797'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
run_sql_up("create-face-matches-table")


def downgrade() -> None:
run_sql_down("create-face-matches-table")
25 changes: 25 additions & 0 deletions migrations/versions/36c3d68f547f_create_notifications_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""create-notifications-table

Revision ID: 36c3d68f547f
Revises: 4ecce8f0b1bd
Create Date: 2026-03-12 18:05:49.743263

"""
from typing import Sequence, Union

from migrations.helper import run_sql_down, run_sql_up


# revision identifiers, used by Alembic.
revision: str = '36c3d68f547f'
down_revision: Union[str, Sequence[str], None] = '4ecce8f0b1bd'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
run_sql_up("create-notifications-table")


def downgrade() -> None:
run_sql_down("create-notifications-table")
25 changes: 25 additions & 0 deletions migrations/versions/3ebf22bc9118_create_events_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""create-events-table

Revision ID: 3ebf22bc9118
Revises: 4c6c265d0d15
Create Date: 2026-03-12 18:05:08.081468

"""
from typing import Sequence, Union

from migrations.helper import run_sql_down, run_sql_up


# revision identifiers, used by Alembic.
revision: str = '3ebf22bc9118'
down_revision: Union[str, Sequence[str], None] = '4c6c265d0d15'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
run_sql_up("create-events-table")


def downgrade() -> None:
run_sql_down("create-events-table")
28 changes: 28 additions & 0 deletions migrations/versions/4c6c265d0d15_add_users_profile_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""add-users-profile-fields

Revision ID: 4c6c265d0d15
Revises: b037dbfdbb1f
Create Date: 2026-03-12 18:04:51.055109

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '4c6c265d0d15'
down_revision: Union[str, Sequence[str], None] = 'b037dbfdbb1f'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
"""Upgrade schema."""
pass


def downgrade() -> None:
"""Downgrade schema."""
pass
Loading
Loading