feat: Add new scripts and update project structure for database management and user authentication

This commit introduces several new scripts for managing database operations, including user creation, permission grants, and data migrations. It also adds new documentation files to guide users through the setup and configuration processes. Additionally, the project structure is updated to enhance organization and maintainability, ensuring a smoother development experience for contributors. These changes support the ongoing transition to a web-based architecture and improve overall project functionality.
This commit is contained in:
Tanya
2026-01-06 13:53:24 -05:00
parent 713584dc04
commit de2144be2a
175 changed files with 35854 additions and 0 deletions
@@ -0,0 +1,30 @@
-- Migration: Add email verification columns to users table
-- Run this migration on the punimtag_auth database
-- Add email_verified column (defaults to false for new users, true for existing users)
ALTER TABLE users
ADD COLUMN IF NOT EXISTS email_verified BOOLEAN NOT NULL DEFAULT true;
-- Add email_confirmation_token column
ALTER TABLE users
ADD COLUMN IF NOT EXISTS email_confirmation_token VARCHAR(255) UNIQUE;
-- Add email_confirmation_token_expiry column
ALTER TABLE users
ADD COLUMN IF NOT EXISTS email_confirmation_token_expiry TIMESTAMP;
-- Create index on email_confirmation_token for faster lookups
CREATE INDEX IF NOT EXISTS idx_users_email_confirmation_token ON users(email_confirmation_token);
-- Update existing users to have verified emails (for backward compatibility)
-- Only update users that don't have the token set (meaning they were created before this migration)
UPDATE users
SET email_verified = true
WHERE email_confirmation_token IS NULL;
@@ -0,0 +1,32 @@
-- Migration: Add inappropriate_photo_reports table for reporting inappropriate photos
-- This table tracks photos reported by users as inappropriate, pending admin review
-- Run this in the punimtag_auth database
CREATE TABLE IF NOT EXISTS inappropriate_photo_reports (
id SERIAL PRIMARY KEY,
photo_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
status VARCHAR(50) DEFAULT 'pending' CHECK (status IN ('pending', 'reviewed', 'dismissed')),
reported_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
reviewed_at TIMESTAMP,
reviewed_by INTEGER,
review_notes TEXT,
CONSTRAINT fk_inappropriate_photo_reports_user
FOREIGN KEY (user_id)
REFERENCES users(id)
ON DELETE CASCADE,
-- Prevent duplicate reports from same user for same photo
CONSTRAINT uq_photo_user_report UNIQUE (photo_id, user_id)
);
-- Create indexes for efficient queries
CREATE INDEX IF NOT EXISTS idx_inappropriate_photo_reports_photo_id ON inappropriate_photo_reports(photo_id);
CREATE INDEX IF NOT EXISTS idx_inappropriate_photo_reports_user_id ON inappropriate_photo_reports(user_id);
CREATE INDEX IF NOT EXISTS idx_inappropriate_photo_reports_status ON inappropriate_photo_reports(status);
CREATE INDEX IF NOT EXISTS idx_inappropriate_photo_reports_reported_at ON inappropriate_photo_reports(reported_at);
-- Add comment to table
COMMENT ON TABLE inappropriate_photo_reports IS 'Stores reports of inappropriate photos submitted by users, pending admin review';
@@ -0,0 +1,17 @@
-- Migration: Add is_active column to users table
-- Run this migration on the punimtag_auth database
-- Add is_active column (defaults to true for all users)
ALTER TABLE users
ADD COLUMN IF NOT EXISTS is_active BOOLEAN NOT NULL DEFAULT true;
-- Update existing users to be active (for backward compatibility)
UPDATE users
SET is_active = true
WHERE is_active IS NULL;
@@ -0,0 +1,19 @@
-- Migration: Add password reset token columns to users table
-- Run this migration on the punimtag_auth database
-- Add password_reset_token column
ALTER TABLE users
ADD COLUMN IF NOT EXISTS password_reset_token VARCHAR(255) UNIQUE;
-- Add password_reset_token_expiry column
ALTER TABLE users
ADD COLUMN IF NOT EXISTS password_reset_token_expiry TIMESTAMP;
-- Create index on password_reset_token for faster lookups
CREATE INDEX IF NOT EXISTS idx_users_password_reset_token ON users(password_reset_token);
@@ -0,0 +1,32 @@
-- Migration: Add pending_photos table for photo uploads
-- This table tracks photos uploaded by users that are pending admin approval
-- Run this in the punimtag_auth database
CREATE TABLE IF NOT EXISTS pending_photos (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL,
filename VARCHAR(255) NOT NULL,
original_filename VARCHAR(255) NOT NULL,
file_path TEXT NOT NULL,
file_size INTEGER NOT NULL,
mime_type VARCHAR(100) NOT NULL,
status VARCHAR(50) DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'rejected')),
submitted_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
reviewed_at TIMESTAMP,
reviewed_by INTEGER,
rejection_reason TEXT,
CONSTRAINT fk_pending_photos_user
FOREIGN KEY (user_id)
REFERENCES users(id)
ON DELETE CASCADE
);
-- Create indexes for efficient queries
CREATE INDEX IF NOT EXISTS idx_pending_photos_user_id ON pending_photos(user_id);
CREATE INDEX IF NOT EXISTS idx_pending_photos_status ON pending_photos(status);
CREATE INDEX IF NOT EXISTS idx_pending_photos_submitted_at ON pending_photos(submitted_at);
-- Add comment to table
COMMENT ON TABLE pending_photos IS 'Stores photos uploaded by users that are pending admin approval';
@@ -0,0 +1,32 @@
-- Migration: Add photo_favorites table for user favorites
-- This table tracks photos favorited by users
-- Run this in the punimtag_auth database
CREATE TABLE IF NOT EXISTS photo_favorites (
id SERIAL PRIMARY KEY,
photo_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
favorited_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_photo_favorites_user
FOREIGN KEY (user_id)
REFERENCES users(id)
ON DELETE CASCADE,
-- Prevent duplicate favorites from same user for same photo
CONSTRAINT uq_photo_user_favorite UNIQUE (photo_id, user_id)
);
-- Create indexes for efficient queries
CREATE INDEX IF NOT EXISTS idx_photo_favorites_photo_id ON photo_favorites(photo_id);
CREATE INDEX IF NOT EXISTS idx_photo_favorites_user_id ON photo_favorites(user_id);
CREATE INDEX IF NOT EXISTS idx_photo_favorites_favorited_at ON photo_favorites(favorited_at);
-- Add comment to table
COMMENT ON TABLE photo_favorites IS 'Stores user favorites for photos';
@@ -0,0 +1,16 @@
-- Migration: Add report_comment column to inappropriate_photo_reports table
-- Run this in the punimtag_auth database
ALTER TABLE inappropriate_photo_reports
ADD COLUMN IF NOT EXISTS report_comment TEXT;
COMMENT ON COLUMN inappropriate_photo_reports.report_comment IS 'Optional short message submitted by the reporting user';
@@ -0,0 +1,21 @@
-- Migration: Add has_write_access column to users table
-- Run this as a PostgreSQL superuser or with appropriate permissions
-- Add the has_write_access column with default false
ALTER TABLE users
ADD COLUMN IF NOT EXISTS has_write_access BOOLEAN NOT NULL DEFAULT false;
-- Create an index on has_write_access for faster queries
CREATE INDEX IF NOT EXISTS idx_users_has_write_access ON users(has_write_access);
-- Update existing users: only admins should have write access initially
-- (You may want to adjust this based on your needs)
UPDATE users
SET has_write_access = false
WHERE has_write_access IS NULL;
-- Verify the column was added
SELECT column_name, data_type, column_default
FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'has_write_access';
@@ -0,0 +1,19 @@
-- Migration: Make name column required (NOT NULL) in users table
-- Run this as a PostgreSQL superuser or with appropriate permissions
-- Prerequisites: All existing users must have a non-null name value
-- First, ensure all existing users have a name (safety check)
-- This should not update any rows if all users already have names
UPDATE users
SET name = email
WHERE name IS NULL;
-- Alter the column to be NOT NULL
ALTER TABLE users
ALTER COLUMN name SET NOT NULL;
-- Verify the column constraint
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = 'users' AND column_name = 'name';