package bootstate

import (
	"context"
	"database/sql"
)

// TableExistsRaw reports whether a table named `table` exists in the
// connection's current database. Relocated verbatim from internal/bootstrap
// (autonumber_seed.go's tableExistsRaw) so both the bootstrap path and relocated
// control-plane code reach it through a neutral sibling. The query and return
// shape are byte-for-byte identical to the original local helper.
func TableExistsRaw(ctx context.Context, rawDB *sql.DB, table string) (bool, error) {
	var n int
	err := rawDB.QueryRowContext(ctx,
		"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES "+
			"WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?",
		table,
	).Scan(&n)
	if err != nil {
		return false, err
	}
	return n > 0, nil
}
