SET @add_product_taxable = (
  SELECT IF(
    EXISTS(
      SELECT 1 FROM information_schema.columns
      WHERE table_schema = DATABASE()
        AND table_name = 'products'
        AND column_name = 'taxable'
    ),
    'SELECT 1',
    'ALTER TABLE products ADD COLUMN taxable BOOLEAN NOT NULL DEFAULT TRUE AFTER tax_rate'
  )
);
PREPARE add_product_taxable_stmt FROM @add_product_taxable;
EXECUTE add_product_taxable_stmt;
DEALLOCATE PREPARE add_product_taxable_stmt;

UPDATE products SET taxable = tax_rate > 0;

INSERT INTO app_settings (setting_key, setting_value)
VALUES ('tax.gstRate', '0.1')
ON DUPLICATE KEY UPDATE setting_value = setting_value;
