gohorsejobs/backend/migrations/010_seed_super_admin.sql
Tiago Yamamoto ae4a3e5e63 feat: migrate from UUID v4 to UUID v7
Migrations:
- Fix 010_seed_super_admin.sql: only use columns from migration 001
- Add 021_create_uuid_v7_function.sql: PostgreSQL uuid_generate_v7() function
- Add 022_migrate_to_uuid_v7.sql: update notifications, tickets, job_payments to use v7

Seeder:
- Create seeder-api/src/utils/uuid.js with uuidv7() function
- Update notifications.js to use uuidv7() instead of randomUUID()

Docs:
- Update DATABASE.md with UUID v7 section and benefits

UUID v7 benefits:
- Time-ordered (sortable by creation time)
- Better index performance than v4
- RFC 9562 compliant
2025-12-24 11:19:26 -03:00

32 lines
1.2 KiB
SQL

-- Migration: Create Super Admin and System Company
-- Description: Inserts the default System Company and Super Admin user.
-- Uses unified tables (companies, users, user_roles)
-- NOTE: This runs before migration 020 adds extra columns, so only use existing columns
-- 1. Insert System Company (for SuperAdmin context)
INSERT INTO companies (name, slug, type, document, email, description, verified, active)
VALUES (
'GoHorse System',
'gohorse-system',
'system',
'00.000.000/0001-91',
'admin@gohorsejobs.com',
'{"tagline": "System Administration Tenant"}',
true,
true
) ON CONFLICT (slug) DO NOTHING;
-- 2. Insert Super Admin User (using only columns from migration 001)
-- WARNING: This hash is generated WITHOUT PASSWORD_PEPPER.
-- For development only. Use seeder-api for proper user creation with pepper.
INSERT INTO users (identifier, password_hash, role, full_name, active)
VALUES (
'superadmin',
'$2a$10$UWrE9xN39lVagJHlXZsxwOVI3NRSEd1VJ6UzMblW6LOxNmsOZtj9K', -- placeholder
'superadmin',
'Super Administrator',
true
) ON CONFLICT (identifier) DO NOTHING;
-- NOTE: user_roles table is created in migration 020, so we skip role assignment here.
-- The seeder-api will handle proper user creation with all fields.