-- +goose Up
SET @has_col := (
  SELECT COUNT(*)
  FROM information_schema.columns
  WHERE table_schema = DATABASE()
    AND table_name = 'user_microsoft_oauth_tokens'
    AND column_name = 'refresh_token_expires_at'
);
SET @sql := IF(
  @has_col = 0,
  'ALTER TABLE user_microsoft_oauth_tokens ADD COLUMN refresh_token_expires_at DATETIME(3) NULL AFTER access_token_expires_at',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

-- +goose Down
SET @has_col := (
  SELECT COUNT(*)
  FROM information_schema.columns
  WHERE table_schema = DATABASE()
    AND table_name = 'user_microsoft_oauth_tokens'
    AND column_name = 'refresh_token_expires_at'
);
SET @sql := IF(
  @has_col = 1,
  'ALTER TABLE user_microsoft_oauth_tokens DROP COLUMN refresh_token_expires_at',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
