-- 015_AddStandardAccountNumber.sql
-- Adds Erhvervsstyrelsens standardkontonummer field for SAF-T 2.0 compliance
-- Required by January 2027 per Danish bookkeeping law (bogføringsloven)

-- Add the standard_account_number column
ALTER TABLE account_read_models
ADD COLUMN IF NOT EXISTS standard_account_number VARCHAR(10);

-- Create index for efficient lookups by standard account number
-- Useful for SAF-T export and reporting
CREATE INDEX IF NOT EXISTS idx_account_standard_number
ON account_read_models(company_id, standard_account_number)
WHERE standard_account_number IS NOT NULL;

-- Add comment for documentation
COMMENT ON COLUMN account_read_models.standard_account_number IS
    'Erhvervsstyrelsens standardkontonummer for SAF-T rapportering. Mapping til officiel dansk kontoplan.';
