BREAKING CHANGE: Removed core_companies, core_users, core_user_roles tables Migrations: - Create 020_unify_schema.sql: adds tenant_id, email, name to users table - Create user_roles table (replaces core_user_roles) - Disable 009_create_core_tables.sql (renamed to .disabled) - Update 010_seed_super_admin.sql to use unified tables Backend Repositories: - company_repository.go: use companies table with INT id - user_repository.go: use users/user_roles with INT id conversion Seeders: - All seeders now use companies/users/user_roles tables - Removed all core_* table insertions - Query companies by slug to get SERIAL id This eliminates the redundancy between core_* and legacy tables.
39 lines
1.4 KiB
SQL
39 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)
|
|
|
|
-- 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
|
|
-- WARNING: This hash is generated WITHOUT PASSWORD_PEPPER.
|
|
-- For development only. Use seeder-api for proper user creation.
|
|
-- Password: "Admin@2025!" (should be created by seeder with proper pepper)
|
|
INSERT INTO users (identifier, password_hash, role, full_name, email, name, status, tenant_id)
|
|
SELECT
|
|
'superadmin',
|
|
'$2a$10$UWrE9xN39lVagJHlXZsxwOVI3NRSEd1VJ6UzMblW6LOxNmsOZtj9K', -- placeholder, seeder will update
|
|
'superadmin',
|
|
'Super Administrator',
|
|
'admin@gohorsejobs.com',
|
|
'Super Administrator',
|
|
'active',
|
|
c.id
|
|
FROM companies c WHERE c.slug = 'gohorse-system'
|
|
ON CONFLICT (identifier) DO NOTHING;
|
|
|
|
-- 3. Assign Super Admin Role
|
|
INSERT INTO user_roles (user_id, role)
|
|
SELECT u.id, 'SUPER_ADMIN'
|
|
FROM users u WHERE u.identifier = 'superadmin'
|
|
ON CONFLICT (user_id, role) DO NOTHING;
|