gohorsejobs/backend/migrations/010_seed_super_admin.sql
Tiago Yamamoto d3c06f5564 feat: expand testing, add fast seeder options, hardcode superadmin
- start.sh: Add options 8 (Seed LITE - skip cities) and 9 (Run All Tests)
- seeder: Add seed:lite, seed:fast scripts and --skip-locations flag
- seeder: Remove superadmin creation (now via backend migration)
- backend: Update 010_seed_super_admin.sql with hardcoded hash (Admin@2025! + pepper)
- backend: Expand jwt_service_test.go with 5 new tests (+10% coverage)
- frontend: Fix api.test.ts URL duplication bug, add error handling tests
- seeder: Add SQL data files to .gitignore
2025-12-24 17:07:45 -03:00

43 lines
1.4 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)
-- HARDCODED: This is the official superadmin - password: Admin@2025! (with pepper: gohorse-pepper)
-- 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
-- Hash: bcrypt(Admin@2025! + gohorse-pepper) - HARDCODED for consistency
INSERT INTO users (identifier, password_hash, role, full_name, email, status, active)
VALUES (
'superadmin',
'$2a$10$/AodyEEQtKCjdeNThEUFee6QE/KvEBTzi1AnqQ78nwavkT1XFnw/6',
'superadmin',
'Super Administrator',
'admin@gohorsejobs.com',
'active',
true
) ON CONFLICT (identifier) DO UPDATE SET
password_hash = EXCLUDED.password_hash,
status = 'active';
-- 3. Assign superadmin role (if user_roles table exists)
DO $$
BEGIN
IF EXISTS (SELECT FROM pg_tables WHERE tablename = 'user_roles') THEN
INSERT INTO user_roles (user_id, role)
SELECT id, 'superadmin' FROM users WHERE identifier = 'superadmin'
ON CONFLICT (user_id, role) DO NOTHING;
END IF;
END $$;