ALTER TABLE safety_documents
    ADD COLUMN tenant_id INTEGER,
    ADD COLUMN branch_id INTEGER;
CREATE INDEX safety_documents_tenant_idx ON safety_documents(tenant_id);
CREATE INDEX safety_documents_branch_idx ON safety_documents(branch_id);

ALTER TABLE safety_document_versions
    ADD COLUMN tenant_id INTEGER,
    ADD COLUMN branch_id INTEGER;
CREATE INDEX safety_document_versions_tenant_idx ON safety_document_versions(tenant_id);
CREATE INDEX safety_document_versions_branch_idx ON safety_document_versions(branch_id);

ALTER TABLE policy_acknowledgments
    ADD COLUMN tenant_id INTEGER,
    ADD COLUMN branch_id INTEGER;
CREATE INDEX policy_acknowledgments_tenant_idx ON policy_acknowledgments(tenant_id);
CREATE INDEX policy_acknowledgments_branch_idx ON policy_acknowledgments(branch_id);

ALTER TABLE ohs_inspection_audits
    ADD COLUMN tenant_id INTEGER,
    ADD COLUMN branch_id INTEGER;
CREATE INDEX ohs_inspection_audits_tenant_idx ON ohs_inspection_audits(tenant_id);
CREATE INDEX ohs_inspection_audits_branch_idx ON ohs_inspection_audits(branch_id);

UPDATE safety_documents SET tenant_id = 1, branch_id = 1 WHERE tenant_id IS NULL;
UPDATE safety_document_versions SET tenant_id = 1, branch_id = 1 WHERE tenant_id IS NULL;
UPDATE policy_acknowledgments SET tenant_id = 1, branch_id = 1 WHERE tenant_id IS NULL;
UPDATE ohs_inspection_audits SET tenant_id = 1, branch_id = 1 WHERE tenant_id IS NULL;
