-- ============================================================
-- Run this INSIDE your MASTER database (after importing master_database.sql)
-- This registers your EXISTING old database as your first company/tenant.
-- Your old data stays exactly where it is - nothing gets moved or deleted.
-- ============================================================

-- Step 1: Register the company (edit company_name / company_code as you like)
INSERT INTO tenants (company_name, company_code, db_host, db_name, db_user, db_pass, status)
VALUES (
    'ABC Monsters',                          -- your actual company name (change this)
    'ABCM001',                               -- any short unique code (change this)
    'localhost',
    'adrieltech_stock_management_app',       -- your existing DB name
    'adrieltech_stock_management_app',       -- your existing DB user
    ';SWC,$3pNQ%]NprH',                      -- your existing DB password
    'active'
);

-- Step 2: Note the new tenant's id (usually 1 if this is the first row)
-- Check it with: SELECT id FROM tenants WHERE company_code = 'ABCM001';

-- Step 3: Register the login(s) that should route to this company.
-- FIRST check what email(s) actually exist in your OLD database:
--     SELECT name, email FROM adrieltech_stock_management_app.users;
-- Then use that email below (NOT the placeholder - your login may have
-- already been changed from the original default).
INSERT INTO tenant_user_index (email, tenant_id)
VALUES (
    'PASTE_YOUR_ACTUAL_ADMIN_EMAIL_HERE',
    (SELECT id FROM tenants WHERE company_code = 'ABCM001')
);

-- If you have more than one existing user in the old database who should be
-- able to log in, repeat Step 3 for each of their emails.
