ALTER TABLE employee_exits
    ADD COLUMN IF NOT EXISTS tenant_id INTEGER,
    ADD COLUMN IF NOT EXISTS branch_id INTEGER;
CREATE INDEX IF NOT EXISTS employee_exits_tenant_idx ON employee_exits(tenant_id);
CREATE INDEX IF NOT EXISTS employee_exits_branch_idx ON employee_exits(branch_id);

ALTER TABLE exit_clearances
    ADD COLUMN IF NOT EXISTS tenant_id INTEGER,
    ADD COLUMN IF NOT EXISTS branch_id INTEGER;
CREATE INDEX IF NOT EXISTS exit_clearances_tenant_idx ON exit_clearances(tenant_id);
CREATE INDEX IF NOT EXISTS exit_clearances_branch_idx ON exit_clearances(branch_id);

ALTER TABLE exit_approvals
    ADD COLUMN IF NOT EXISTS tenant_id INTEGER,
    ADD COLUMN IF NOT EXISTS branch_id INTEGER;
CREATE INDEX IF NOT EXISTS exit_approvals_tenant_idx ON exit_approvals(tenant_id);
CREATE INDEX IF NOT EXISTS exit_approvals_branch_idx ON exit_approvals(branch_id);

ALTER TABLE exit_interviews
    ADD COLUMN IF NOT EXISTS tenant_id INTEGER,
    ADD COLUMN IF NOT EXISTS branch_id INTEGER;
CREATE INDEX IF NOT EXISTS exit_interviews_tenant_idx ON exit_interviews(tenant_id);
CREATE INDEX IF NOT EXISTS exit_interviews_branch_idx ON exit_interviews(branch_id);

ALTER TABLE exit_feedback
    ADD COLUMN IF NOT EXISTS tenant_id INTEGER,
    ADD COLUMN IF NOT EXISTS branch_id INTEGER;
CREATE INDEX IF NOT EXISTS exit_feedback_tenant_idx ON exit_feedback(tenant_id);
CREATE INDEX IF NOT EXISTS exit_feedback_branch_idx ON exit_feedback(branch_id);

UPDATE employee_exits SET tenant_id = 1, branch_id = 1 WHERE tenant_id IS NULL;
UPDATE exit_clearances SET tenant_id = 1, branch_id = 1 WHERE tenant_id IS NULL;
UPDATE exit_approvals SET tenant_id = 1, branch_id = 1 WHERE tenant_id IS NULL;
UPDATE exit_interviews SET tenant_id = 1, branch_id = 1 WHERE tenant_id IS NULL;
UPDATE exit_feedback SET tenant_id = 1, branch_id = 1 WHERE tenant_id IS NULL;
