veza/veza-backend-api/migrations/931_add_refresh_tokens_updated_at.sql
senke d0f403018d [FIX] ISSUE-001 & ISSUE-002: Fix authentication workflow for MVP
ISSUE-001: Auto-verify email on registration
- Set IsVerified: true in Register() to allow immediate login
- Removes blocking email verification requirement for MVP

ISSUE-002: Generate tokens in Register
- Modified Register() signature to return (*User, *TokenPair, error)
- Added JWT token generation after user creation
- Store refresh token in database
- Updated handlers to use returned tokens
- Added nil checks for JWTService and refreshTokenService

Changes:
- veza-backend-api/internal/core/auth/service.go
- veza-backend-api/internal/handlers/auth.go
- veza-backend-api/internal/core/auth/handler.go
- REAL_ISSUES_TODOLIST.json

Note: Backend needs to be recompiled and restarted for changes to take effect.
2026-01-04 01:44:13 +01:00

34 lines
1,008 B
PL/PgSQL

-- 931_add_refresh_tokens_updated_at.sql
-- Add updated_at column to refresh_tokens table to match GORM model
BEGIN;
-- Add updated_at column if it doesn't exist
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'refresh_tokens'
AND column_name = 'updated_at'
) THEN
ALTER TABLE public.refresh_tokens
ADD COLUMN updated_at TIMESTAMPTZ DEFAULT NOW();
-- Update existing rows to have updated_at = created_at
UPDATE public.refresh_tokens
SET updated_at = created_at
WHERE updated_at IS NULL;
-- Make it NOT NULL after setting values
ALTER TABLE public.refresh_tokens
ALTER COLUMN updated_at SET NOT NULL;
RAISE NOTICE 'Added updated_at column to refresh_tokens table';
ELSE
RAISE NOTICE 'Column updated_at already exists in refresh_tokens table';
END IF;
END $$;
COMMIT;